2
Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
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
15
/* #define NO_UNZIPH_STUFF */
16
#define UNZIP_INTERNAL
22
char *exts2swap = NULL; /* Extensions to swap (actually, directory names) */
24
int stat(char *filename,struct stat *res)
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 */
34
if (SWI_OS_File_5(filename,&type,&load,&exec,(int *)&res->st_size,&attr)!=NULL)
48
res->st_mode = ((attr & 0001) << 8) | ((attr & 0002) << 6) |
49
((attr & 0020) >> 2) | ((attr & 0040) >> 4);
53
res->st_mode |= S_IFREG;
55
case 2: /* Directory */
56
res->st_mode |= S_IFDIR | 0700;
58
case 3: /* Image file */
60
res->st_mode |= S_IFDIR | 0700;
62
res->st_mode |= S_IFREG;
66
if ((((unsigned int) load) >> 20) == 0xfff) { /* date stamped file */
67
register unsigned int t1, t2, tc;
69
t1 = (unsigned int) (exec);
70
t2 = (unsigned int) (load & 0xff);
76
t2 -= 0x33; /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */
78
t1 = (t1 / 100) + (t2 * 42949673U); /* 0x100000000 / 100 = 42949672.96 */
79
t1 -= (t2 / 25); /* compensate for .04 error */
81
res->st_atime = res->st_mtime = res->st_ctime = t1;
84
res->st_atime = res->st_mtime = res->st_ctime = 0;
91
DIR *opendir(char *dirname)
98
thisdir=(DIR *)malloc(sizeof(DIR));
102
thisdir->dirname=(char *)malloc(strlen(dirname)+1);
103
if (thisdir->dirname==NULL) {
108
strcpy(thisdir->dirname,dirname);
109
if (thisdir->dirname[strlen(thisdir->dirname)-1]=='.')
110
thisdir->dirname[strlen(thisdir->dirname)-1]=0;
112
if (er=SWI_OS_File_5(thisdir->dirname,&type,NULL,NULL,NULL,&attr),er!=NULL ||
113
type<=1 || (type==3 && !uO.scanimage))
115
free(thisdir->dirname);
120
thisdir->buf=malloc(DIR_BUFSIZE);
121
if (thisdir->buf==NULL) {
122
free(thisdir->dirname);
127
thisdir->size=DIR_BUFSIZE;
134
struct dirent *readdir(DIR *d)
136
static struct dirent dent;
138
if (d->read==0) { /* no more objects read in the buffer */
139
if (d->offset==-1) { /* no more objects to read */
144
if (SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,DIR_BUFSIZE,NULL)!=NULL)
152
d->act=(char *)d->buf;
154
else { /* some object is ready in buffer */
156
d->act=(char *)(d->act+strlen(d->act)+1);
159
strcpy(dent.d_name,d->act);
160
dent.d_namlen=strlen(dent.d_name);
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 */
165
SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,0,NULL);
170
void closedir(DIR *d)
174
if (d->dirname!=NULL)
180
char *f; /* file to delete */
181
/* Delete the file *f, returning non-zero on failure. */
187
er=SWI_OS_FSControl_37(f,canon,&size);
189
er=SWI_OS_FSControl_27(canon,0x100);
192
er=SWI_OS_FSControl_27(f,0x100);
204
if ((s = malloc(len + 1)) == NULL)
211
if (SWI_OS_File_5(s,&objtype,NULL,NULL,NULL,NULL)!=NULL) {
215
if (objtype<2 || (!uO.scanimage && objtype==3)) {
216
/* this is a file or it doesn't exist */
220
if (SWI_OS_File_6(s)!=NULL) {
230
int chmod(char *file, int mode)
232
/*************** NOT YET IMPLEMENTED!!!!!! ******************/
233
/* I don't know if this will be needed or not... */
239
void setfiletype(char *fname,int ftype)
242
sprintf(str,"SetType %s &%3.3X",fname,ftype);
246
void getRISCOSexts(char *envstr)
248
char *envptr; /* value returned by getenv */
250
envptr = getenv(envstr);
251
if (envptr == NULL || *envptr == 0) return;
253
exts2swap=malloc(1+strlen(envptr));
254
if (exts2swap == NULL)
257
strcpy(exts2swap, envptr);
260
int checkext(char *suff)
262
register char *extptr = exts2swap ? exts2swap : "";
263
register char *suffptr;
268
e=*extptr; s=*suffptr;
269
while (e && e!=':' && s && s!='.' && s!='/' && e==s) {
270
e=*++extptr; s=*++suffptr;
273
if (s=='.' || s=='/') s=0;
277
while(*extptr!=':' && *extptr!='\0') /* skip to next extension */
285
void swapext(char *name, char *exptr)
288
register char *p1=exptr+1;
289
register char *p2=ext;
292
while(*p1 && *p1!='.' && *p1!='/')
303
*p1=(extchar=='/'?'.':'/');
306
void remove_prefix(void)
308
SWI_DDEUtils_Prefix(NULL);
311
void set_prefix(void)
316
if (SWI_OS_FSControl_37("@",pref,&size)!=NULL)
321
if (pref=malloc(size),pref!=NULL) {
322
if (SWI_OS_FSControl_37("@",pref,&size)!=NULL) {
327
if (SWI_DDEUtils_Prefix(pref)==NULL) {
328
atexit(remove_prefix);
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
348
struct tm *riscos_localtime(const time_t *timer)
350
time_t localt=*timer;
352
localt+=SWI_Read_Timezone()/100;
354
return localtime(&localt);
357
struct tm *riscos_gmtime(const time_t *timer)
359
time_t localt=*timer;
361
localt+=SWI_Read_Timezone()/100;
363
return gmtime(&localt);