Rev 4921 | Rev 5215 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4921 | Rev 5198 | ||
---|---|---|---|
Line 20... | Line 20... | ||
20 | #include "io.h" |
20 | #include "io.h" |
Line 21... | Line 21... | ||
21 | 21 | ||
22 | #undef erro |
22 | #undef erro |
Line -... | Line 23... | ||
- | 23 | extern int errno; |
|
- | 24 | ||
- | 25 | static inline int is_slash(char c) |
|
- | 26 | { |
|
- | 27 | return c=='/' || c=='\\'; |
|
- | 28 | } |
|
- | 29 | ||
- | 30 | void fix_slashes(char * in,char * out) |
|
- | 31 | { |
|
- | 32 | int slash_count; |
|
- | 33 | ||
- | 34 | for(slash_count=1;in && out && *in;in++) |
|
- | 35 | { |
|
- | 36 | if(is_slash(*in)) |
|
- | 37 | { |
|
- | 38 | slash_count++; |
|
- | 39 | continue; |
|
- | 40 | } |
|
- | 41 | else |
|
- | 42 | { |
|
- | 43 | if(slash_count) |
|
- | 44 | { |
|
- | 45 | slash_count=0; |
|
- | 46 | *out++='/'; |
|
- | 47 | } |
|
- | 48 | *out++=*in; |
|
- | 49 | } |
|
- | 50 | } |
|
- | 51 | *out='\0'; |
|
- | 52 | }; |
|
- | 53 | ||
- | 54 | ||
- | 55 | void buildpath(char *buf, const char* file) |
|
- | 56 | { |
|
- | 57 | char *ptr; |
|
- | 58 | ||
- | 59 | ptr = buf + strlen(buf); |
|
- | 60 | ||
- | 61 | while (*file) |
|
- | 62 | { |
|
- | 63 | if (file[0] == '.' && file[1] == 0) |
|
- | 64 | break; |
|
- | 65 | ||
- | 66 | if (file[0] == '.' && file[1] == '/') |
|
- | 67 | { |
|
- | 68 | file+=2; |
|
- | 69 | continue; |
|
- | 70 | }; |
|
- | 71 | ||
- | 72 | if (file[0] == '.' && file[1] == '.' && |
|
- | 73 | (file[2] == 0 || file[2] == '/')) |
|
- | 74 | { |
|
- | 75 | while (ptr > buf && ptr[-1] != '/') |
|
- | 76 | --ptr; |
|
- | 77 | file+=2; |
|
- | 78 | if (*file == 0) |
|
- | 79 | break; |
|
- | 80 | ++file; |
|
- | 81 | continue; |
|
- | 82 | } |
|
- | 83 | *ptr++ = '/'; |
|
- | 84 | if (*file == '/') |
|
- | 85 | ++file; |
|
- | 86 | while (*file && *file!='/') |
|
- | 87 | *ptr++ = *file++; |
|
- | 88 | } |
|
- | 89 | *ptr = 0; |
|
- | 90 | }; |
|
- | 91 | ||
- | 92 | static char *getccwd(char *buf, size_t size) |
|
- | 93 | { |
|
- | 94 | int bsize; |
|
- | 95 | __asm__ __volatile__( |
|
- | 96 | "int $0x40" |
|
- | 97 | :"=a"(bsize) |
|
- | 98 | :"a"(30),"b"(2),"c"(buf), "d"(size) |
|
- | 99 | :"memory"); |
|
- | 100 | ||
- | 101 | return buf; |
|
23 | extern int errno; |
102 | }; |
24 | 103 | ||
- | 104 | int open (const char * filename, int flags, ...) |
|
- | 105 | { |
|
25 | int open (const char * filename, int flags, ...) |
106 | char buf[1024]; |
26 | { |
107 | |
27 | __io_handle *ioh; |
108 | __io_handle *ioh; |
28 | fileinfo_t info; |
109 | fileinfo_t info; |
29 | int iomode, rwmode, offset; |
110 | int iomode, rwmode, offset; |
Line 35... | Line 116... | ||
35 | { |
116 | { |
36 | errno = EMFILE; |
117 | errno = EMFILE; |
37 | return (-1); |
118 | return (-1); |
38 | }; |
119 | }; |
Line -... | Line 120... | ||
- | 120 | ||
- | 121 | if (filename[0]=='/') |
|
- | 122 | { |
|
- | 123 | strcpy(buf,filename); |
|
- | 124 | } |
|
- | 125 | else |
|
- | 126 | { |
|
39 | 127 | getccwd(buf, 1024); |
|
- | 128 | buildpath(buf, filename); |
|
- | 129 | } |
|
- | 130 | ||
Line 40... | Line 131... | ||
40 | // path = getfullpath(name); |
131 | // printf("%s %s\n", __FUNCTION__, buf); |
Line 41... | Line 132... | ||
41 | 132 | ||
42 | err = get_fileinfo(filename, &info); |
133 | err = get_fileinfo(buf, &info); |
43 | 134 | ||
44 | if( flags & O_EXCL && |
135 | if( flags & O_EXCL && |
Line 52... | Line 143... | ||
52 | } |
143 | } |
Line 53... | Line 144... | ||
53 | 144 | ||
54 | if( err ) |
145 | if( err ) |
55 | { |
146 | { |
56 | if(flags & O_CREAT) |
147 | if(flags & O_CREAT) |
57 | err=create_file(filename); |
148 | err=create_file(buf); |
58 | if( err ) |
149 | if( err ) |
59 | { |
150 | { |
60 | errno = EACCES; |
151 | errno = EACCES; |
61 | return -1; |
152 | return -1; |
62 | }; |
153 | }; |
Line 63... | Line 154... | ||
63 | }; |
154 | }; |
64 | 155 | ||
Line 65... | Line 156... | ||
65 | if( flags & O_TRUNC ) |
156 | if( flags & O_TRUNC ) |
Line 66... | Line 157... | ||
66 | set_file_size(filename, 0); |
157 | set_file_size(buf, 0); |
Line 90... | Line 181... | ||
90 | if( flags & O_BINARY ) |
181 | if( flags & O_BINARY ) |
91 | iomode |= _BINARY; |
182 | iomode |= _BINARY; |
92 | } else |
183 | } else |
93 | iomode |= _BINARY; |
184 | iomode |= _BINARY; |
Line 94... | Line 185... | ||
94 | 185 | ||
95 | ioh->name = strdup(filename); |
186 | ioh->name = strdup(buf); |
96 | ioh->offset = offset; |
187 | ioh->offset = offset; |
97 | ioh->mode = iomode; |
188 | ioh->mode = iomode; |
98 | ioh->read = read_file; |
189 | ioh->read = read_file; |
Line -... | Line 190... | ||
- | 190 | ioh->write = write_file; |
|
- | 191 | ||
99 | ioh->write = write_file; |
192 | // printf("%s %s\n", __FUNCTION__, ioh->name); |
100 | 193 |