2
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
4
See the accompanying file LICENSE, version 1999-Oct-05 or later
5
(the contents of which are also included in zip.h) for terms of use.
6
If, for some reason, both of these files are missing, the Info-ZIP license
7
also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
9
/*** macopen.c; stuff only required for the Mac port ***/
26
extern char *zipfile; /* filename of the Zipfile */
27
extern char *tempzip; /* Temporary zip file name */
29
extern MacZipGlobals MacZip;
32
/* don't include "osdep.h" otherwise we will trap into endless loop */
38
FILE *MacFopen(const char *path, const char *mode)
40
static char TruncPath[NAME_MAX];
45
/* open zipfile or tempzip */
46
if (strcmp(zipfile,path) == 0)
48
GetCompletePath(MacZip.ZipFullPath,path,&MacZip.ZipFileSpec,&err);
49
err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
50
printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);
51
if (CheckMountedVolumes(MacZip.ZipFullPath) > 1)
52
DoWarnUserDupVol(MacZip.ZipFullPath);
54
/* tempfile should appear in the same directory of the zipfile
55
-> save path of zipfile */
56
TruncFilename(TruncPath, MacZip.ZipFullPath);
57
return fopen(MacZip.ZipFullPath, mode);
60
if (strcmp(tempzip,path) == 0)
61
{ /* add path of zipfile */
62
sstrcat(TruncPath,tempzip);
63
GetCompletePath(MacZip.TempZipFullPath,TruncPath,&MacZip.TempZipFileSpec,&err);
64
err = PrintUserHFSerr((err != -43) && (err != 0), err, path);
65
printerr("GetCompletePath:",err,err,__LINE__,__FILE__,path);
67
return fopen(MacZip.TempZipFullPath, mode);
70
printerr("MacFopen:",err,err,__LINE__,__FILE__,path);
77
int MacOpen(const char *path,int oflag, ...)
79
char RealFname[NAME_MAX];
83
RfDfFilen2Real(RealFname,path, MacZip.MacZipMode, MacZip.DataForkOnly, &MacZip.CurrentFork);
84
/* convert to real fname and init global var MacZip.CurrentFork !! */
86
switch (MacZip.CurrentFork)
90
return my_open(RealFname, oflag);
95
return my_open( RealFname, oflag | O_RSRC);
98
default: /* for now (Zip ver 2.3b) MacOpen should never reach this point */
99
{ /* however, this may change in the future ... */
100
printerr("open: no resource / datafork ",-1,-1,__LINE__,__FILE__,path);
109
int destroy(char *path)
111
static char lastpath[NAME_MAX];
112
char currpath[NAME_MAX];
113
static Boolean FirstCall = true;
118
RfDfFilen2Real(currpath, path, MacZip.MacZipMode, MacZip.DataForkOnly, &MacZip.CurrentFork);
120
if (FirstCall == true)
123
rc = remove(currpath);
125
else if (strcmp(currpath,lastpath) == 0) return 0; /* ignore, file is already deleted */
126
else rc = remove(currpath); /* we are removeing all the files only by their
127
pathname this is dangerous on a mac but there is no other way without
128
a complete rewrite of the port */
130
strcpy(lastpath,currpath);
139
/* this function replaces the function "replace()" defined in fileio.c */
140
int replace(char *new_f, char *temp_f) /* destination and source file names */
143
char newfname[NAME_MAX];
145
AssertStr(new_f,new_f)
146
AssertStr(temp_f,temp_f)
150
GetFilename(newfname, new_f);
152
/* check zipfile name and tempfile name */
153
/* we are using this function only for replacing the tempfile with the zipfile */
154
if ((strcmp(zipfile,new_f) == 0) || (strcmp(tempzip,temp_f) == 0))
156
remove(MacZip.ZipFullPath);
158
/* rename the temp file to the zip file */
159
err = rename(MacZip.TempZipFullPath,MacZip.ZipFullPath);
160
printerr("rename:",err,err,__LINE__,__FILE__,MacZip.TempZipFullPath);
161
if (err != 0) return ZE_CREAT;
164
else return ZE_CREAT;
170
/* we are removeing all the files only by their
171
pathname this is dangerous on a mac but there is no
172
other way without a complete rewrite of the port */
174
int destroy(char *path)
176
static char lastpath[NAME_MAX];
177
static FSSpec trashfolder;
178
static Boolean FirstCall = true;
180
static Boolean Immediate_File_Deletion = false;
181
char currpath[NAME_MAX], *envptr;
185
/* init this function */
186
if ((path == NULL) ||
196
RfDfFilen2Real(currpath, path, MacZip.MacZipMode,
197
MacZip.DataForkOnly, &MacZip.CurrentFork);
198
GetCompletePath(currpath,currpath,&fileToDelete, &err);
200
if (FirstCall == true)
203
sstrcpy(lastpath,currpath);
204
err = FSpFindFolder(fileToDelete.vRefNum, kTrashFolderType,
205
kDontCreateFolder,&trashfolder);
206
printerr("FSpFindFolder:",err,err,__LINE__,__FILE__,path);
208
envptr = getenv("Immediate_File_Deletion");
209
if (!(envptr == (char *)NULL || *envptr == '\0'))
211
if (stricmp(envptr,"yes") == 0)
212
Immediate_File_Deletion = true;
214
Immediate_File_Deletion = false;
217
if (Immediate_File_Deletion)
219
err = FSpDelete(&fileToDelete);
223
err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
224
fileToDelete.name, trashfolder.parID, trashfolder.name);
228
if (strcmp(currpath,lastpath) == 0)
230
return 0; /* ignore, file is already deleted */
235
if (Immediate_File_Deletion)
237
err = FSpDelete(&fileToDelete);
238
sstrcpy(lastpath,path);
242
err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
243
fileToDelete.name, trashfolder.parID, trashfolder.name);
245
/* -48 = file is already existing so we have to rename it before
250
if (fileToDelete.name[0] >= 28) /* cut filename if to long */
251
fileToDelete.name[0] = 28;
252
P2CStr(fileToDelete.name);
253
sprintf(currpath,"%s~%d",(char *)fileToDelete.name,Num);
255
C2PStr((char *)fileToDelete.name);
256
err = HRename (fileToDelete.vRefNum, fileToDelete.parID,
257
fileToDelete.name, (unsigned char *) currpath);
258
err = CatMove (fileToDelete.vRefNum, fileToDelete.parID,
259
(unsigned char *) currpath, trashfolder.parID,
264
sstrcpy(lastpath,currpath);
270
#endif /* #ifdef MACZIP */
276
* int open(const char *path, int oflag)
278
* Opens a file stream.
280
int my_open(char *path, int oflag)
286
Boolean targetIsFolder, wasAliased;
290
/* Setup permission */
291
if ((oflag & 0x03) == O_RDWR)
292
permission = fsRdWrPerm;
294
permission = (oflag & O_RDONLY) ? fsRdPerm : 0 + (oflag & O_WRONLY) ? fsWrPerm : 0;
296
FSpLocationFromFullPath(strlen(path),path, &spec);
297
if ((oflag & (O_ALIAS | O_NRESOLVE)) == 0)
298
ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased);
299
hpb.fileParam.ioNamePtr = spec.name;
300
hpb.fileParam.ioVRefNum = spec.vRefNum;
301
hpb.fileParam.ioDirID = spec.parID;
302
hpb.ioParam.ioPermssn = permission;
304
if (oflag & O_RSRC) /* open the resource fork of the file */
305
err = PBHOpenRFSync(&hpb);
306
else /* open the data fork of the file */
307
err = PBHOpenDFSync(&hpb);
309
if ((err == fnfErr) && (oflag & O_CREAT)) {
310
hpb.fileParam.ioFlVersNum = 0;
311
err = PBHCreateSync(&hpb);
313
/* Set the finder info */
315
unsigned long isbinary = oflag & O_BINARY;
317
hpb.fileParam.ioFlFndrInfo.fdType = '\?\?\?\?';
318
hpb.fileParam.ioFlFndrInfo.fdCreator = '\?\?\?\?';
319
hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
320
if (oflag & O_ALIAS) /* set the alias bit */
321
hpb.fileParam.ioFlFndrInfo.fdFlags = kIsAlias;
322
else /* clear all flags */
323
hpb.fileParam.ioFlFndrInfo.fdFlags = 0;
326
hpb.fileParam.ioFlCrDat = hpb.fileParam.ioFlMdDat = secs;
327
PBHSetFInfoSync(&hpb);
330
if (err && (err != dupFNErr)) {
331
errno = err; return -1;
334
if (oflag & O_RSRC) /* open the resource fork of the file */
335
err = PBHOpenRFSync(&hpb);
336
else /* open the data fork of the file */
337
err = PBHOpenDFSync(&hpb);
340
if (err && (err != dupFNErr) && (err != opWrErr)) {
341
errno = err; return -1;
344
if (oflag & O_TRUNC) {
347
pb.ioRefNum = hpb.ioParam.ioRefNum;
349
err = PBSetEOFSync((ParmBlkPtr)&pb);
351
errno = err; return -1;
355
if (oflag & O_APPEND) lseek(hpb.ioParam.ioRefNum,0,SEEK_END);
357
return (hpb.ioParam.ioRefNum);
365
const char *BOINC_RCSID_9a1fb79b04 = "$Id: macopen.c 4979 2005-01-02 18:29:53Z ballen $";