Rev 9346 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9346 | Rev 9952 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * they apply. |
13 | * they apply. |
14 | */ |
14 | */ |
15 | #include |
15 | #include |
16 | #include |
16 | #include |
17 | #include |
17 | #include |
18 | #include |
18 | #include |
- | 19 | ||
19 | #include "glue.h" |
20 | #include "glue.h" |
20 | #include "io.h" |
21 | #include "io.h" |
Line 21... | Line 22... | ||
21 | 22 | ||
22 | #undef erro |
23 | #undef errno |
Line -... | Line 24... | ||
- | 24 | extern int errno; |
|
- | 25 | ||
- | 26 | extern int write_file(const char *path,const void *buff, |
|
- | 27 | size_t offset, size_t count, size_t *writes); |
|
- | 28 | ||
- | 29 | extern int read_file(const char *path, void *buff, |
|
23 | extern int errno; |
30 | size_t offset, size_t count, size_t *reads); |
24 | 31 | ||
25 | static inline int is_slash(char c) |
32 | static inline int is_slash(char c) |
26 | { |
33 | { |
Line 47... | Line 54... | ||
47 | } |
54 | } |
48 | *out++=*in; |
55 | *out++=*in; |
49 | } |
56 | } |
50 | } |
57 | } |
51 | *out='\0'; |
58 | *out='\0'; |
52 | }; |
59 | } |
Line 53... | Line 60... | ||
53 | 60 | ||
54 | 61 | ||
55 | void buildpath(char *buf, const char* file) |
62 | void buildpath(char *buf, const char* file) |
Line 87... | Line 94... | ||
87 | ++file; |
94 | ++file; |
88 | while (*file && *file!='/') |
95 | while (*file && *file!='/') |
89 | *ptr++ = *file++; |
96 | *ptr++ = *file++; |
90 | } |
97 | } |
91 | *ptr = 0; |
98 | *ptr = 0; |
92 | }; |
99 | } |
93 | - | ||
94 | static char *getccwd(char *buf, size_t size) |
- | |
95 | { |
- | |
96 | int bsize; |
- | |
97 | __asm__ __volatile__( |
- | |
98 | "int $0x40" |
- | |
99 | :"=a"(bsize) |
- | |
100 | :"a"(30),"b"(2),"c"(buf), "d"(size) |
- | |
101 | :"memory"); |
- | |
102 | - | ||
103 | return buf; |
- | |
104 | }; |
- | |
Line 105... | Line 100... | ||
105 | 100 | ||
106 | int open (const char * filename, int flags, ...) |
101 | int open (const char * filename, int flags, ...) |
107 | { |
102 | { |
Line 108... | Line 103... | ||
108 | char buf[1024]; |
103 | char buf[1024]; |
109 | 104 | ||
110 | __io_handle *ioh; |
105 | __io_handle *ioh; |
111 | fileinfo_t info; |
106 | ksys_file_info_t info; |
112 | int iomode, rwmode, offset; |
107 | int iomode, rwmode, offset; |
Line 113... | Line 108... | ||
113 | int hid; |
108 | int hid; |
Line 125... | Line 120... | ||
125 | { |
120 | { |
126 | strcpy(buf,filename); |
121 | strcpy(buf,filename); |
127 | } |
122 | } |
128 | else |
123 | else |
129 | { |
124 | { |
130 | getccwd(buf, 1024); |
125 | _ksys_getcwd(buf, 1024); |
131 | buildpath(buf, filename); |
126 | buildpath(buf, filename); |
132 | } |
127 | } |
Line 133... | Line 128... | ||
133 | 128 | ||
Line 134... | Line 129... | ||
134 | err = get_fileinfo(buf, &info); |
129 | err = _ksys_file_info(buf, &info); |
135 | 130 | ||
136 | if( flags & O_EXCL && |
131 | if (flags & O_EXCL && |
137 | flags & O_CREAT ) |
132 | flags & O_CREAT ) |
138 | { |
133 | { |
139 | if( !err ) |
134 | if (!err) |
140 | { |
135 | { |
141 | errno = EEXIST; |
136 | errno = EEXIST; |
142 | __io_free(hid); |
137 | __io_free(hid); |
143 | return (-1); |
138 | return (-1); |
Line 144... | Line 139... | ||
144 | }; |
139 | } |
145 | } |
140 | } |
146 | 141 | ||
147 | if( err ) |
142 | if (err) |
148 | { |
143 | { |
149 | if(flags & O_CREAT) |
144 | if(flags & O_CREAT) |
150 | err=create_file(buf); |
145 | err = _ksys_file_create(buf).status; |
151 | if( err ) |
146 | if(err) |
152 | { |
147 | { |
153 | errno = EACCES; |
148 | errno = EACCES; |
154 | __io_free(hid); |
149 | __io_free(hid); |
Line 155... | Line 150... | ||
155 | return -1; |
150 | return -1; |
156 | }; |
151 | }; |
Line 157... | Line 152... | ||
157 | }; |
152 | }; |
Line 158... | Line 153... | ||
158 | 153 | ||
Line 175... | Line 170... | ||
175 | 170 | ||
176 | if( flags & O_APPEND ) |
171 | if (flags & O_APPEND) |
177 | { |
172 | { |
178 | iomode |= _APPEND; |
173 | iomode |= _APPEND; |
179 | offset = info.size; |
174 | offset = info.size; |
Line 180... | Line 175... | ||
180 | }; |
175 | } |
181 | 176 | ||
182 | if( flags & (O_BINARY|O_TEXT) ) |
177 | if (flags & (O_BINARY|O_TEXT)) |
183 | { |
178 | { |
- | 179 | if (flags & O_BINARY) |
|
184 | if( flags & O_BINARY ) |
180 | iomode |= _BINARY; |
- | 181 | } |
|
185 | iomode |= _BINARY; |
182 | else |
- | 183 | { |
|
Line 186... | Line 184... | ||
186 | } else |
184 | iomode |= _BINARY; |
187 | iomode |= _BINARY; |
185 | } |
188 | 186 | ||
189 | ioh->name = strdup(buf); |
187 | ioh->name = strdup(buf); |
190 | ioh->offset = offset; |
188 | ioh->offset = offset; |
Line 191... | Line 189... | ||
191 | ioh->mode = iomode; |
189 | ioh->mode = iomode; |
192 | ioh->read = read_file; |
190 | ioh->read = read_file; |
193 | ioh->write = write_file; |
- | |
194 | - |