Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6725 | siemargl | 1 | /* |
2 | Copyright (c) 1990-2002 Info-ZIP. All rights reserved. |
||
3 | |||
4 | See the accompanying file LICENSE, version 2000-Apr-09 or later |
||
5 | (the contents of which are also included in unzip.h) for terms of use. |
||
6 | If, for some reason, all these files are missing, the Info-ZIP license |
||
7 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
||
8 | */ |
||
9 | /* riscos.c */ |
||
10 | |||
11 | #include |
||
12 | #include |
||
13 | #include |
||
14 | |||
15 | /* #define NO_UNZIPH_STUFF */ |
||
16 | #define UNZIP_INTERNAL |
||
17 | #include "unzip.h" |
||
18 | #include "riscos.h" |
||
19 | |||
20 | #define MAXEXT 16 |
||
21 | |||
22 | char *exts2swap = NULL; /* Extensions to swap (actually, directory names) */ |
||
23 | |||
24 | int stat(char *filename,struct stat *res) |
||
25 | { |
||
26 | int attr; /* object attributes */ |
||
27 | unsigned int load; /* load address */ |
||
28 | unsigned int exec; /* exec address */ |
||
29 | int type; /* type: 0 not found, 1 file, 2 dir, 3 image */ |
||
30 | |||
31 | if (!res) |
||
32 | return -1; |
||
33 | |||
34 | if (SWI_OS_File_5(filename,&type,&load,&exec,(int *)&res->st_size,&attr)!=NULL) |
||
35 | return -1; |
||
36 | |||
37 | if (type==0) |
||
38 | return -1; |
||
39 | |||
40 | res->st_dev=0; |
||
41 | res->st_ino=0; |
||
42 | res->st_nlink=0; |
||
43 | res->st_uid=1; |
||
44 | res->st_gid=1; |
||
45 | res->st_rdev=0; |
||
46 | res->st_blksize=1024; |
||
47 | |||
48 | res->st_mode = ((attr & 0001) << 8) | ((attr & 0002) << 6) | |
||
49 | ((attr & 0020) >> 2) | ((attr & 0040) >> 4); |
||
50 | |||
51 | switch (type) { |
||
52 | case 1: /* File */ |
||
53 | res->st_mode |= S_IFREG; |
||
54 | break; |
||
55 | case 2: /* Directory */ |
||
56 | res->st_mode |= S_IFDIR | 0700; |
||
57 | break; |
||
58 | case 3: /* Image file */ |
||
59 | if (uO.scanimage) |
||
60 | res->st_mode |= S_IFDIR | 0700; |
||
61 | else |
||
62 | res->st_mode |= S_IFREG; |
||
63 | break; |
||
64 | } |
||
65 | |||
66 | if ((((unsigned int) load) >> 20) == 0xfff) { /* date stamped file */ |
||
67 | register unsigned int t1, t2, tc; |
||
68 | |||
69 | t1 = (unsigned int) (exec); |
||
70 | t2 = (unsigned int) (load & 0xff); |
||
71 | |||
72 | tc = 0x6e996a00U; |
||
73 | if (t1 < tc) |
||
74 | t2--; |
||
75 | t1 -= tc; |
||
76 | t2 -= 0x33; /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */ |
||
77 | |||
78 | t1 = (t1 / 100) + (t2 * 42949673U); /* 0x100000000 / 100 = 42949672.96 */ |
||
79 | t1 -= (t2 / 25); /* compensate for .04 error */ |
||
80 | |||
81 | res->st_atime = res->st_mtime = res->st_ctime = t1; |
||
82 | } |
||
83 | else |
||
84 | res->st_atime = res->st_mtime = res->st_ctime = 0; |
||
85 | |||
86 | return 0; |
||
87 | } |
||
88 | |||
89 | #ifndef SFX |
||
90 | |||
91 | DIR *opendir(char *dirname) |
||
92 | { |
||
93 | DIR *thisdir; |
||
94 | int type; |
||
95 | int attr; |
||
96 | os_error *er; |
||
97 | |||
98 | thisdir=(DIR *)malloc(sizeof(DIR)); |
||
99 | if (thisdir==NULL) |
||
100 | return NULL; |
||
101 | |||
102 | thisdir->dirname=(char *)malloc(strlen(dirname)+1); |
||
103 | if (thisdir->dirname==NULL) { |
||
104 | free(thisdir); |
||
105 | return NULL; |
||
106 | } |
||
107 | |||
108 | strcpy(thisdir->dirname,dirname); |
||
109 | if (thisdir->dirname[strlen(thisdir->dirname)-1]=='.') |
||
110 | thisdir->dirname[strlen(thisdir->dirname)-1]=0; |
||
111 | |||
112 | if (er=SWI_OS_File_5(thisdir->dirname,&type,NULL,NULL,NULL,&attr),er!=NULL || |
||
113 | type<=1 || (type==3 && !uO.scanimage)) |
||
114 | { |
||
115 | free(thisdir->dirname); |
||
116 | free(thisdir); |
||
117 | return NULL; |
||
118 | } |
||
119 | |||
120 | thisdir->buf=malloc(DIR_BUFSIZE); |
||
121 | if (thisdir->buf==NULL) { |
||
122 | free(thisdir->dirname); |
||
123 | free(thisdir); |
||
124 | return NULL; |
||
125 | } |
||
126 | |||
127 | thisdir->size=DIR_BUFSIZE; |
||
128 | thisdir->offset=0; |
||
129 | thisdir->read=0; |
||
130 | |||
131 | return thisdir; |
||
132 | } |
||
133 | |||
134 | struct dirent *readdir(DIR *d) |
||
135 | { |
||
136 | static struct dirent dent; |
||
137 | |||
138 | if (d->read==0) { /* no more objects read in the buffer */ |
||
139 | if (d->offset==-1) { /* no more objects to read */ |
||
140 | return NULL; |
||
141 | } |
||
142 | |||
143 | d->read=255; |
||
144 | if (SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,DIR_BUFSIZE,NULL)!=NULL) |
||
145 | return NULL; |
||
146 | |||
147 | if (d->read==0) { |
||
148 | d->offset=-1; |
||
149 | return NULL; |
||
150 | } |
||
151 | d->read--; |
||
152 | d->act=(char *)d->buf; |
||
153 | } |
||
154 | else { /* some object is ready in buffer */ |
||
155 | d->read--; |
||
156 | d->act=(char *)(d->act+strlen(d->act)+1); |
||
157 | } |
||
158 | |||
159 | strcpy(dent.d_name,d->act); |
||
160 | dent.d_namlen=strlen(dent.d_name); |
||
161 | |||
162 | /* If we're returning the last item, check if there are any more. |
||
163 | * If there are, nothing will happen; if not, then d->offset = -1 */ |
||
164 | if (!d->read) |
||
165 | SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,0,NULL); |
||
166 | |||
167 | return &dent; |
||
168 | } |
||
169 | |||
170 | void closedir(DIR *d) |
||
171 | { |
||
172 | if (d->buf!=NULL) |
||
173 | free(d->buf); |
||
174 | if (d->dirname!=NULL) |
||
175 | free(d->dirname); |
||
176 | free(d); |
||
177 | } |
||
178 | |||
179 | int unlink(f) |
||
180 | char *f; /* file to delete */ |
||
181 | /* Delete the file *f, returning non-zero on failure. */ |
||
182 | { |
||
183 | os_error *er; |
||
184 | char canon[256]; |
||
185 | int size=255; |
||
186 | |||
187 | er=SWI_OS_FSControl_37(f,canon,&size); |
||
188 | if (er==NULL) { |
||
189 | er=SWI_OS_FSControl_27(canon,0x100); |
||
190 | } |
||
191 | else { |
||
192 | er=SWI_OS_FSControl_27(f,0x100); |
||
193 | } |
||
194 | return (int)er; |
||
195 | } |
||
196 | |||
197 | int rmdir(char *d) |
||
198 | { |
||
199 | int objtype; |
||
200 | char *s; |
||
201 | int len; |
||
202 | |||
203 | len = strlen(d); |
||
204 | if ((s = malloc(len + 1)) == NULL) |
||
205 | return -1; |
||
206 | |||
207 | strcpy(s,d); |
||
208 | if (s[len-1]=='.') |
||
209 | s[len-1]=0; |
||
210 | |||
211 | if (SWI_OS_File_5(s,&objtype,NULL,NULL,NULL,NULL)!=NULL) { |
||
212 | free(s); |
||
213 | return -1; |
||
214 | } |
||
215 | if (objtype<2 || (!uO.scanimage && objtype==3)) { |
||
216 | /* this is a file or it doesn't exist */ |
||
217 | free(s); |
||
218 | return -1; |
||
219 | } |
||
220 | if (SWI_OS_File_6(s)!=NULL) { |
||
221 | free(s); |
||
222 | return -1; |
||
223 | } |
||
224 | free(s); |
||
225 | return 0; |
||
226 | } |
||
227 | |||
228 | #endif /* !SFX */ |
||
229 | |||
230 | int chmod(char *file, int mode) |
||
231 | { |
||
232 | /*************** NOT YET IMPLEMENTED!!!!!! ******************/ |
||
233 | /* I don't know if this will be needed or not... */ |
||
234 | file=file; |
||
235 | mode=mode; |
||
236 | return 0; |
||
237 | } |
||
238 | |||
239 | void setfiletype(char *fname,int ftype) |
||
240 | { |
||
241 | char str[256]; |
||
242 | sprintf(str,"SetType %s &%3.3X",fname,ftype); |
||
243 | SWI_OS_CLI(str); |
||
244 | } |
||
245 | |||
246 | void getRISCOSexts(char *envstr) |
||
247 | { |
||
248 | char *envptr; /* value returned by getenv */ |
||
249 | |||
250 | envptr = getenv(envstr); |
||
251 | if (envptr == NULL || *envptr == 0) return; |
||
252 | |||
253 | exts2swap=malloc(1+strlen(envptr)); |
||
254 | if (exts2swap == NULL) |
||
255 | return; |
||
256 | |||
257 | strcpy(exts2swap, envptr); |
||
258 | } |
||
259 | |||
260 | int checkext(char *suff) |
||
261 | { |
||
262 | register char *extptr = exts2swap ? exts2swap : ""; |
||
263 | register char *suffptr; |
||
264 | register int e,s; |
||
265 | |||
266 | while(*extptr) { |
||
267 | suffptr=suff; |
||
268 | e=*extptr; s=*suffptr; |
||
269 | while (e && e!=':' && s && s!='.' && s!='/' && e==s) { |
||
270 | e=*++extptr; s=*++suffptr; |
||
271 | } |
||
272 | if (e==':') e=0; |
||
273 | if (s=='.' || s=='/') s=0; |
||
274 | if (!e && !s) { |
||
275 | return 1; |
||
276 | } |
||
277 | while(*extptr!=':' && *extptr!='\0') /* skip to next extension */ |
||
278 | extptr++; |
||
279 | if (*extptr!='\0') |
||
280 | extptr++; |
||
281 | } |
||
282 | return 0; |
||
283 | } |
||
284 | |||
285 | void swapext(char *name, char *exptr) |
||
286 | { |
||
287 | char ext[MAXEXT]; |
||
288 | register char *p1=exptr+1; |
||
289 | register char *p2=ext; |
||
290 | int extchar=*exptr; |
||
291 | |||
292 | while(*p1 && *p1!='.' && *p1!='/') |
||
293 | *p2++=*p1++; |
||
294 | *p2=0; |
||
295 | p2=exptr-1; |
||
296 | p1--; |
||
297 | while(p2 >= name) |
||
298 | *p1--=*p2--; |
||
299 | p1=name; |
||
300 | p2=ext; |
||
301 | while(*p2) |
||
302 | *p1++=*p2++; |
||
303 | *p1=(extchar=='/'?'.':'/'); |
||
304 | } |
||
305 | |||
306 | void remove_prefix(void) |
||
307 | { |
||
308 | SWI_DDEUtils_Prefix(NULL); |
||
309 | } |
||
310 | |||
311 | void set_prefix(void) |
||
312 | { |
||
313 | char *pref; |
||
314 | int size=0; |
||
315 | |||
316 | if (SWI_OS_FSControl_37("@",pref,&size)!=NULL) |
||
317 | return; |
||
318 | |||
319 | size=1-size; |
||
320 | |||
321 | if (pref=malloc(size),pref!=NULL) { |
||
322 | if (SWI_OS_FSControl_37("@",pref,&size)!=NULL) { |
||
323 | free(pref); |
||
324 | return; |
||
325 | } |
||
326 | |||
327 | if (SWI_DDEUtils_Prefix(pref)==NULL) { |
||
328 | atexit(remove_prefix); |
||
329 | } |
||
330 | |||
331 | free(pref); |
||
332 | } |
||
333 | } |
||
334 | |||
335 | #ifdef localtime |
||
336 | # undef localtime |
||
337 | #endif |
||
338 | |||
339 | #ifdef gmtime |
||
340 | # undef gmtime |
||
341 | #endif |
||
342 | |||
343 | /* Acorn's implementation of localtime() and gmtime() |
||
344 | * doesn't consider the timezone offset, so we have to |
||
345 | * add it before calling the library functions |
||
346 | */ |
||
347 | |||
348 | struct tm *riscos_localtime(const time_t *timer) |
||
349 | { |
||
350 | time_t localt=*timer; |
||
351 | |||
352 | localt+=SWI_Read_Timezone()/100; |
||
353 | |||
354 | return localtime(&localt); |
||
355 | } |
||
356 | |||
357 | struct tm *riscos_gmtime(const time_t *timer) |
||
358 | { |
||
359 | time_t localt=*timer; |
||
360 | |||
361 | localt+=SWI_Read_Timezone()/100; |
||
362 | |||
363 | return gmtime(&localt); |
||
364 | }2>=1>>><>><> |