Skip to content

Latest commit

 

History

History
959 lines (774 loc) · 28.8 KB

macclassic.c

File metadata and controls

959 lines (774 loc) · 28.8 KB
 
Mar 11, 2007
Mar 11, 2007
2
* Mac OS classic support routines for PhysicsFS.
Mar 11, 2007
Mar 11, 2007
4
* Please see the file LICENSE.txt in the source's root directory.
5
6
7
8
*
* This file written by Ryan C. Gordon.
*/
Mar 11, 2007
Mar 11, 2007
9
10
11
12
13
#define __PHYSICSFS_INTERNAL__
#include "physfs_platforms.h"
#ifdef PHYSFS_PLATFORM_MACCLASSIC
Jan 31, 2003
Jan 31, 2003
14
#include <stdio.h>
15
16
#include <stdlib.h>
#include <string.h>
Dec 29, 2003
Dec 29, 2003
17
#include <ctype.h>
Apr 6, 2002
Apr 6, 2002
18
19
20
/*
* Most of the API calls in here are, according to ADC, available since
Mar 11, 2007
Mar 11, 2007
21
* Mac OS 8.1. I don't think I used any Mac OS 9 or CarbonLib-specific
Apr 6, 2002
Apr 6, 2002
22
* functions. There might be one or two 8.5 calls, and perhaps when the
Mar 11, 2007
Mar 11, 2007
23
* ADC docs say "Available in Mac OS 8.1" they really mean "this works
Apr 6, 2002
Apr 6, 2002
24
25
* with System 6, but we don't want to hear about it at this point."
*
Mar 11, 2007
Mar 11, 2007
26
* IsAliasFile() showed up in Mac OS 8.5. You can duplicate this code with
Apr 6, 2002
Apr 6, 2002
27
* PBGetCatInfoSync(), which is an older API, if you hope the bits in the
Mar 11, 2007
Mar 11, 2007
28
* catalog info never change (which they won't for, say, Mac OS 8.1).
Apr 6, 2002
Apr 6, 2002
29
30
31
32
33
34
35
36
37
* See Apple Technote FL-30:
* http://developer.apple.com/technotes/fl/fl_30.html
*
* If you want to use weak pointers and Gestalt, and choose the correct
* code to use during __PHYSFS_platformInit(), I'll accept a patch, but
* chances are, it wasn't worth the time it took to write this, let alone
* implement that.
*/
38
39
40
41
#include <OSUtils.h>
#include <Processes.h>
#include <Files.h>
Apr 2, 2002
Apr 2, 2002
42
43
44
#include <TextUtils.h>
#include <Resources.h>
#include <MacMemory.h>
Apr 3, 2002
Apr 3, 2002
45
#include <Events.h>
Apr 5, 2002
Apr 5, 2002
46
#include <DriverGestalt.h>
Apr 6, 2002
Apr 6, 2002
47
#include <Aliases.h>
48
49
50
51
52
#include "physfs_internal.h"
const char *__PHYSFS_platformDirSeparator = ":";
Jul 28, 2002
Jul 28, 2002
53
Jul 28, 2002
Jul 28, 2002
54
static const char *get_macos_error_string(OSErr err)
Jul 28, 2002
Jul 28, 2002
55
56
57
58
59
60
{
if (err == noErr)
return(NULL);
switch (err)
{
Jul 28, 2002
Jul 28, 2002
61
62
63
64
65
case fnfErr: return(ERR_NO_SUCH_FILE);
case notOpenErr: return(ERR_NO_SUCH_VOLUME);
case dirFulErr: return(ERR_DIRECTORY_FULL);
case dskFulErr: return(ERR_DISK_FULL);
case nsvErr: return(ERR_NO_SUCH_VOLUME);
Jul 28, 2002
Jul 28, 2002
66
67
68
69
70
case ioErr: return(ERR_IO_ERROR);
case bdNamErr: return(ERR_BAD_FILENAME);
case fnOpnErr: return(ERR_NOT_A_HANDLE);
case eofErr: return(ERR_PAST_EOF);
case posErr: return(ERR_SEEK_OUT_OF_RANGE);
Jul 28, 2002
Jul 28, 2002
71
72
73
74
75
case tmfoErr: return(ERR_TOO_MANY_HANDLES);
case wPrErr: return(ERR_VOL_LOCKED_HW);
case fLckdErr: return(ERR_FILE_LOCKED);
case vLckdErr: return(ERR_VOL_LOCKED_SW);
case fBsyErr: return(ERR_FILE_OR_DIR_BUSY);
Jan 31, 2003
Jan 31, 2003
76
case dupFNErr: return(ERR_FILE_EXISTS);
Jul 28, 2002
Jul 28, 2002
77
78
79
80
81
82
83
84
85
86
87
88
case opWrErr: return(ERR_FILE_ALREADY_OPEN_W);
case rfNumErr: return(ERR_INVALID_REFNUM);
case gfpErr: return(ERR_GETTING_FILE_POS);
case volOffLinErr: return(ERR_VOLUME_OFFLINE);
case permErr: return(ERR_PERMISSION_DENIED);
case volOnLinErr: return(ERR_VOL_ALREADY_ONLINE);
case nsDrvErr: return(ERR_NO_SUCH_DRIVE);
case noMacDskErr: return(ERR_NOT_MAC_DISK);
case extFSErr: return(ERR_VOL_EXTERNAL_FS);
case fsRnErr: return(ERR_PROBLEM_RENAME);
case badMDBErr: return(ERR_BAD_MASTER_BLOCK);
case wrPermErr: return(ERR_PERMISSION_DENIED);
Jul 28, 2002
Jul 28, 2002
89
case memFullErr: return(ERR_OUT_OF_MEMORY);
Jul 28, 2002
Jul 28, 2002
90
91
92
93
94
case dirNFErr: return(ERR_NO_SUCH_PATH);
case tmwdoErr: return(ERR_TOO_MANY_HANDLES);
case badMovErr: return(ERR_CANT_MOVE_FORBIDDEN);
case wrgVolTypErr: return(ERR_WRONG_VOL_TYPE);
case volGoneErr: return(ERR_SERVER_VOL_LOST);
Jul 28, 2002
Jul 28, 2002
95
case errFSNameTooLong: return(ERR_BAD_FILENAME);
Jul 28, 2002
Jul 28, 2002
96
case errFSNotAFolder: return(ERR_NOT_A_DIR);
Jan 31, 2003
Jan 31, 2003
97
/*case errFSNotAFile: return(ERR_NOT_A_FILE);*/
Jul 28, 2002
Jul 28, 2002
98
99
100
101
102
103
case fidNotFound: return(ERR_FILE_ID_NOT_FOUND);
case fidExists: return(ERR_FILE_ID_EXISTS);
case afpAccessDenied: return(ERR_ACCESS_DENIED);
case afpNoServer: return(ERR_SERVER_NO_RESPOND);
case afpUserNotAuth: return(ERR_USER_AUTH_FAILED);
case afpPwdExpiredErr: return(ERR_PWORD_EXPIRED);
Jul 28, 2002
Jul 28, 2002
104
105
106
107
108
109
110
case paramErr:
case errFSBadFSRef:
case errFSBadBuffer:
case errFSMissingName:
case errFSBadPosMode:
case errFSBadAllocFlags:
Jan 31, 2003
Jan 31, 2003
111
112
113
case errFSBadItemCount:
case errFSBadSearchParams:
case afpDenyConflict:
Jul 28, 2002
Jul 28, 2002
114
return(ERR_PHYSFS_BAD_OS_CALL);
Jul 28, 2002
Jul 28, 2002
115
Jul 28, 2002
Jul 28, 2002
116
default: return(ERR_MACOS_GENERIC);
Jul 28, 2002
Jul 28, 2002
117
118
119
} /* switch */
return(NULL);
Jul 28, 2002
Jul 28, 2002
120
} /* get_macos_error_string */
Jul 28, 2002
Jul 28, 2002
121
122
Jul 28, 2002
Jul 28, 2002
123
static OSErr oserr(OSErr retval)
Jul 28, 2002
Jul 28, 2002
124
{
Jan 31, 2003
Jan 31, 2003
125
char buf[sizeof (ERR_MACOS_GENERIC) + 32];
Jul 28, 2002
Jul 28, 2002
126
const char *errstr = get_macos_error_string(retval);
Jan 31, 2003
Jan 31, 2003
127
if (strcmp(errstr, ERR_MACOS_GENERIC) == 0)
Jul 28, 2002
Jul 28, 2002
128
{
Mar 16, 2005
Mar 16, 2005
129
sprintf(buf, ERR_MACOS_GENERIC, (int) retval);
Jul 28, 2002
Jul 28, 2002
130
131
132
133
errstr = buf;
} /* if */
if (errstr != NULL)
Jul 28, 2002
Jul 28, 2002
134
__PHYSFS_setError(errstr);
Jul 28, 2002
Jul 28, 2002
135
Jul 28, 2002
Jul 28, 2002
136
return(retval);
Jul 28, 2002
Jul 28, 2002
137
138
139
} /* oserr */
Apr 5, 2002
Apr 5, 2002
140
141
static struct ProcessInfoRec procInfo;
static FSSpec procfsspec;
142
143
144
int __PHYSFS_platformInit(void)
{
Apr 5, 2002
Apr 5, 2002
145
146
OSErr err;
ProcessSerialNumber psn;
Jul 28, 2002
Jul 28, 2002
147
BAIL_IF_MACRO(oserr(GetCurrentProcess(&psn)) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
148
149
150
151
152
memset(&procInfo, '\0', sizeof (ProcessInfoRec));
memset(&procfsspec, '\0', sizeof (FSSpec));
procInfo.processInfoLength = sizeof (ProcessInfoRec);
procInfo.processAppSpec = &procfsspec;
err = GetProcessInformation(&psn, &procInfo);
Jul 28, 2002
Jul 28, 2002
153
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
154
return(1); /* we're golden. */
155
156
157
158
159
160
161
162
163
} /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void)
{
return(1); /* always succeed. */
} /* __PHYSFS_platformDeinit */
Apr 5, 2002
Apr 5, 2002
164
165
166
167
/*
* CD detection code is borrowed from Apple Technical Q&A DV18.
* http://developer.apple.com/qa/dv/dv18.html
*/
Sep 29, 2004
Sep 29, 2004
168
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
Sep 29, 2004
Sep 29, 2004
170
Apr 5, 2002
Apr 5, 2002
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
DriverGestaltParam pb;
DrvQEl *dqp;
OSErr status;
pb.csCode = kDriverGestaltCode;
pb.driverGestaltSelector = kdgDeviceType;
dqp = (DrvQEl *) GetDrvQHdr()->qHead;
while (dqp != NULL)
{
pb.ioCRefNum = dqp->dQRefNum;
pb.ioVRefNum = dqp->dQDrive;
status = PBStatusSync((ParmBlkPtr) &pb);
if ((status == noErr) && (pb.driverGestaltResponse == kdgCDType))
{
Str63 volName;
Sep 29, 2004
Sep 29, 2004
187
size_t size;
Apr 5, 2002
Apr 5, 2002
188
189
190
191
192
193
194
HParamBlockRec hpbr;
memset(&hpbr, '\0', sizeof (HParamBlockRec));
hpbr.volumeParam.ioNamePtr = volName;
hpbr.volumeParam.ioVRefNum = dqp->dQDrive;
hpbr.volumeParam.ioVolIndex = 0;
if (PBHGetVInfoSync(&hpbr) == noErr)
{
Sep 29, 2004
Sep 29, 2004
195
196
197
size = (size_t) volName[0]; /* convert to ASCIZ string... */
memmove(&volName[0], &volName[1], size);
volName[size] = '\0';
Mar 14, 2005
Mar 14, 2005
198
cb(data, (const char *) volName);
Apr 5, 2002
Apr 5, 2002
199
200
201
202
203
} /* if */
} /* if */
dqp = (DrvQEl *) dqp->qLink;
} /* while */
204
205
206
} /* __PHYSFS_platformDetectAvailableCDs */
Apr 6, 2002
Apr 6, 2002
207
static char *convFSSpecToPath(FSSpec *spec, int includeFile)
208
209
210
211
212
213
{
char *ptr;
char *retval = NULL;
UInt32 retLength = 0;
CInfoPBRec infoPB;
Str255 str255;
Apr 6, 2002
Apr 6, 2002
214
215
216
217
str255[0] = spec->name[0];
memcpy(&str255[1], &spec->name[1], str255[0]);
218
memset(&infoPB, '\0', sizeof (CInfoPBRec));
Apr 5, 2002
Apr 5, 2002
219
infoPB.dirInfo.ioNamePtr = str255; /* put name in here. */
Apr 6, 2002
Apr 6, 2002
220
221
222
infoPB.dirInfo.ioVRefNum = spec->vRefNum; /* ID of bin's volume. */
infoPB.dirInfo.ioDrParID = spec->parID; /* ID of bin's dir. */
infoPB.dirInfo.ioFDirIndex = (includeFile) ? 0 : -1;
223
224
225
226
227
228
/* walk the tree back to the root dir (volume), building path string... */
do
{
/* check parent dir of what we last looked at... */
infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
Jul 28, 2002
Jul 28, 2002
229
if (oserr(PBGetCatInfoSync(&infoPB)) != noErr)
230
231
{
if (retval != NULL)
Mar 14, 2005
Mar 14, 2005
232
allocator.Free(retval);
Jul 28, 2002
Jul 28, 2002
233
return(NULL);
Apr 6, 2002
Apr 6, 2002
235
236
237
infoPB.dirInfo.ioFDirIndex = -1; /* look at parent dir next time. */
238
239
/* allocate more space for the retval... */
retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
Mar 14, 2005
Mar 14, 2005
240
ptr = (char *) allocator.Malloc(retLength);
241
242
243
if (ptr == NULL)
{
if (retval != NULL)
Mar 14, 2005
Mar 14, 2005
244
allocator.Free(retval);
245
246
247
248
249
250
251
252
253
254
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
/* prepend new dir to retval and cleanup... */
memcpy(ptr, &str255[1], str255[0]);
ptr[str255[0]] = '\0'; /* null terminate it. */
if (retval != NULL)
{
strcat(ptr, ":");
strcat(ptr, retval);
Mar 14, 2005
Mar 14, 2005
255
allocator.Free(retval);
256
257
258
259
260
} /* if */
retval = ptr;
} while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
return(retval);
Apr 6, 2002
Apr 6, 2002
261
262
263
264
265
266
267
268
269
270
} /* convFSSpecToPath */
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
FSSpec spec;
/* Get the name of the binary's parent directory. */
FSMakeFSSpec(procfsspec.vRefNum, procfsspec.parID, procfsspec.name, &spec);
return(convFSSpecToPath(&spec, 0));
271
272
273
274
275
276
} /* __PHYSFS_platformCalcBaseDir */
char *__PHYSFS_platformGetUserName(void)
{
char *retval = NULL;
Apr 2, 2002
Apr 2, 2002
277
278
279
280
281
282
StringHandle strHandle;
short origResourceFile = CurResFile();
/* use the System resource file. */
UseResFile(0);
/* apparently, -16096 specifies the username. */
Jan 31, 2003
Jan 31, 2003
283
strHandle = GetString(-16096);
Apr 2, 2002
Apr 2, 2002
284
UseResFile(origResourceFile);
Jul 28, 2002
Jul 28, 2002
285
BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
Apr 2, 2002
Apr 2, 2002
286
287
HLock((Handle) strHandle);
Mar 14, 2005
Mar 14, 2005
288
retval = (char *) allocator.Malloc((*strHandle)[0] + 1);
Apr 2, 2002
Apr 2, 2002
289
290
291
292
293
294
295
296
297
if (retval == NULL)
{
HUnlock((Handle) strHandle);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
memcpy(retval, &(*strHandle)[1], (*strHandle)[0]);
retval[(*strHandle)[0]] = '\0'; /* null-terminate it. */
HUnlock((Handle) strHandle);
298
299
300
301
302
303
return(retval);
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void)
{
Apr 6, 2002
Apr 6, 2002
304
#if 0
305
return(NULL); /* bah...use default behaviour, I guess. */
Apr 6, 2002
Apr 6, 2002
306
307
308
309
#else
/* (Hmm. Default behaviour is broken in the base library. :) ) */
return(__PHYSFS_platformCalcBaseDir(NULL));
#endif
310
311
312
313
314
315
316
317
318
319
320
} /* __PHYSFS_platformGetUserDir */
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
{
return(1); /* single threaded. */
} /* __PHYSFS_platformGetThreadID */
int __PHYSFS_platformStricmp(const char *x, const char *y)
{
Dec 29, 2003
Dec 29, 2003
321
322
323
324
325
326
327
328
329
330
331
332
333
int ux, uy;
do
{
ux = toupper((int) *x);
uy = toupper((int) *y);
if (ux != uy)
return((ux > uy) ? 1 : -1);
x++;
y++;
} while ((ux) && (uy));
return(0);
334
335
336
} /* __PHYSFS_platformStricmp */
Dec 29, 2003
Dec 29, 2003
337
int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len)
Nov 9, 2003
Nov 9, 2003
338
{
Dec 29, 2003
Dec 29, 2003
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
int ux, uy;
if (!len)
return(0);
do
{
ux = toupper((int) *x);
uy = toupper((int) *y);
if (ux != uy)
return((ux > uy) ? 1 : -1);
x++;
y++;
len--;
} while ((ux) && (uy) && (len));
return(0);
} /* __PHYSFS_platformStrnicmp */
Nov 9, 2003
Nov 9, 2003
357
358
Apr 6, 2002
Apr 6, 2002
359
static OSErr fnameToFSSpecNoAlias(const char *fname, FSSpec *spec)
Apr 4, 2002
Apr 4, 2002
360
{
Apr 4, 2002
Apr 4, 2002
361
OSErr err;
Apr 4, 2002
Apr 4, 2002
362
Str255 str255;
Jul 11, 2002
Jul 11, 2002
363
int needColon = (strchr(fname, ':') == NULL);
Apr 5, 2002
Apr 5, 2002
364
int len = strlen(fname) + ((needColon) ? 1 : 0);
Apr 4, 2002
Apr 4, 2002
365
366
367
368
369
if (len > 255)
return(bdNamErr);
/* !!! FIXME: What happens with relative pathnames? */
Apr 5, 2002
Apr 5, 2002
370
371
372
373
374
375
376
str255[0] = len;
memcpy(&str255[1], fname, len);
/* probably just a volume name, which seems to need a ':' at the end. */
if (needColon)
str255[len] = ':';
Jul 28, 2002
Jul 28, 2002
377
err = oserr(FSMakeFSSpec(0, 0, str255, spec));
Apr 4, 2002
Apr 4, 2002
378
return(err);
Apr 6, 2002
Apr 6, 2002
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
} /* fnameToFSSpecNoAlias */
static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
{
Boolean alias = 0;
Boolean folder = 0;
OSErr err = fnameToFSSpecNoAlias(fname, spec);
if (err == dirNFErr) /* might be an alias in the middle of the path. */
{
/*
* Has to be at least two ':' chars, or we wouldn't get a
* dir-not-found condition. (no ':' means it was just a volume,
* just one ':' means we would have gotten a fnfErr, if anything.
*/
char *ptr;
char *start;
char *path = alloca(strlen(fname) + 1);
strcpy(path, fname);
ptr = strchr(path, ':');
Jul 23, 2002
Jul 23, 2002
400
BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
Apr 6, 2002
Apr 6, 2002
401
ptr = strchr(ptr + 1, ':');
Jul 23, 2002
Jul 23, 2002
402
BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
Apr 6, 2002
Apr 6, 2002
403
404
*ptr = '\0';
err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
Jul 28, 2002
Jul 28, 2002
405
BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
Apr 6, 2002
Apr 6, 2002
406
407
408
start = ptr;
ptr = strchr(start + 1, ':');
Jul 11, 2002
Jul 11, 2002
409
/* Now check each element of the path for aliases... */
Apr 6, 2002
Apr 6, 2002
410
411
412
413
414
415
416
417
418
do
{
CInfoPBRec infoPB;
memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = spec->name;
infoPB.dirInfo.ioVRefNum = spec->vRefNum;
infoPB.dirInfo.ioDrDirID = spec->parID;
infoPB.dirInfo.ioFDirIndex = 0;
err = PBGetCatInfoSync(&infoPB);
Jul 11, 2002
Jul 11, 2002
419
if (err != noErr) /* not an alias, really just a bogus path. */
Apr 6, 2002
Apr 6, 2002
420
421
422
423
424
return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0)
spec->parID = infoPB.dirInfo.ioDrDirID;
Jul 11, 2002
Jul 11, 2002
425
if (ptr != NULL) /* terminate string after next element. */
Apr 6, 2002
Apr 6, 2002
426
*ptr = '\0';
Jul 11, 2002
Jul 11, 2002
427
Apr 6, 2002
Apr 6, 2002
428
429
430
431
432
433
434
435
436
*start = strlen(start + 1); /* make it a pstring. */
err = FSMakeFSSpec(spec->vRefNum, spec->parID,
(const unsigned char *) start, spec);
if (err != noErr) /* not an alias, really a bogus path. */
return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
if (err != noErr) /* not an alias, really a bogus path. */
return(fnameToFSSpecNoAlias(fname, spec)); /* reset */
Jul 11, 2002
Jul 11, 2002
437
438
start = ptr; /* move to the next element. */
Apr 6, 2002
Apr 6, 2002
439
440
441
442
443
444
445
if (ptr != NULL)
ptr = strchr(start + 1, ':');
} while (start != NULL);
} /* if */
else /* there's something there; make sure final file is not an alias. */
{
Jul 28, 2002
Jul 28, 2002
446
BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
Apr 6, 2002
Apr 6, 2002
447
err = ResolveAliasFileWithMountFlags(spec, 1, &folder, &alias, 0);
Jul 28, 2002
Jul 28, 2002
448
BAIL_IF_MACRO(oserr(err) != noErr, NULL, err);
Apr 6, 2002
Apr 6, 2002
449
450
451
} /* else */
return(noErr); /* w00t. */
Apr 4, 2002
Apr 4, 2002
452
453
454
} /* fnameToFSSpec */
455
456
int __PHYSFS_platformExists(const char *fname)
{
Apr 4, 2002
Apr 4, 2002
457
458
FSSpec spec;
return(fnameToFSSpec(fname, &spec) == noErr);
459
460
461
462
463
} /* __PHYSFS_platformExists */
int __PHYSFS_platformIsSymLink(const char *fname)
{
Apr 6, 2002
Apr 6, 2002
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
OSErr err;
FSSpec spec;
Boolean a = 0;
Boolean f = 0;
CInfoPBRec infoPB;
char *ptr;
char *dir = alloca(strlen(fname) + 1);
BAIL_IF_MACRO(dir == NULL, ERR_OUT_OF_MEMORY, 0);
strcpy(dir, fname);
ptr = strrchr(dir, ':');
if (ptr == NULL) /* just a volume name? Can't be a symlink. */
return(0);
/* resolve aliases up to the actual file... */
*ptr = '\0';
Jul 25, 2002
Jul 25, 2002
479
BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, NULL, 0);
Apr 6, 2002
Apr 6, 2002
480
481
482
483
484
485
486
*ptr = strlen(ptr + 1); /* ptr is now a pascal string. Yikes! */
memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = spec.name;
infoPB.dirInfo.ioVRefNum = spec.vRefNum;
infoPB.dirInfo.ioDrDirID = spec.parID;
infoPB.dirInfo.ioFDirIndex = 0;
Jul 28, 2002
Jul 28, 2002
487
BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, 0);
Apr 6, 2002
Apr 6, 2002
488
489
490
err = FSMakeFSSpec(spec.vRefNum, infoPB.dirInfo.ioDrDirID,
(const unsigned char *) ptr, &spec);
Jul 28, 2002
Jul 28, 2002
491
492
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
BAIL_IF_MACRO(oserr(IsAliasFile(&spec, &a, &f)) != noErr, NULL, 0);
Apr 6, 2002
Apr 6, 2002
493
return(a);
494
495
496
497
498
} /* __PHYSFS_platformIsSymlink */
int __PHYSFS_platformIsDirectory(const char *fname)
{
Apr 4, 2002
Apr 4, 2002
499
500
FSSpec spec;
CInfoPBRec infoPB;
Apr 4, 2002
Apr 4, 2002
501
OSErr err;
Apr 4, 2002
Apr 4, 2002
502
Jul 25, 2002
Jul 25, 2002
503
BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, NULL, 0);
Apr 4, 2002
Apr 4, 2002
504
505
506
memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = spec.name; /* put name in here. */
infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of file's volume. */
Apr 4, 2002
Apr 4, 2002
507
infoPB.dirInfo.ioDrDirID = spec.parID; /* ID of bin's dir. */
Apr 4, 2002
Apr 4, 2002
508
infoPB.dirInfo.ioFDirIndex = 0; /* file (not parent) info. */
Apr 4, 2002
Apr 4, 2002
509
err = PBGetCatInfoSync(&infoPB);
Jul 28, 2002
Jul 28, 2002
510
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
Apr 4, 2002
Apr 4, 2002
511
return((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0);
512
513
514
515
516
517
518
} /* __PHYSFS_platformIsDirectory */
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append)
{
Apr 3, 2002
Apr 3, 2002
519
520
521
522
523
int len = ((prepend) ? strlen(prepend) : 0) +
((append) ? strlen(append) : 0) +
strlen(dirName) + 1;
const char *src;
char *dst;
Mar 14, 2005
Mar 14, 2005
524
char *retval = (char *) allocator.Malloc(len);
Apr 3, 2002
Apr 3, 2002
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
if (prepend != NULL)
{
strcpy(retval, prepend);
dst = retval + strlen(retval);
} /* if */
else
{
*retval = '\0';
dst = retval;
} /* else */
for (src = dirName; *src; src++, dst++)
*dst = ((*src == '/') ? ':' : *src);
*dst = '\0';
return(retval);
543
544
545
546
547
} /* __PHYSFS_platformCvtToDependent */
void __PHYSFS_platformTimeslice(void)
{
Apr 3, 2002
Apr 3, 2002
548
SystemTask();
549
550
551
} /* __PHYSFS_platformTimeslice */
Sep 29, 2004
Sep 29, 2004
552
553
554
/* returns int so we can use BAIL*MACRO... */
static int macClassicEnumerateFiles(const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
555
556
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
557
void *callbackdata)
Apr 5, 2002
Apr 5, 2002
559
560
UInt16 i;
UInt16 max;
Apr 4, 2002
Apr 4, 2002
561
562
563
FSSpec spec;
CInfoPBRec infoPB;
Str255 str255;
Apr 5, 2002
Apr 5, 2002
564
long dirID;
Apr 4, 2002
Apr 4, 2002
565
Jul 25, 2002
Jul 25, 2002
566
BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, NULL, 0);
Apr 4, 2002
Apr 4, 2002
567
Apr 5, 2002
Apr 5, 2002
568
569
570
571
572
573
/* get the dir ID of what we want to enumerate... */
memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = spec.name; /* name of dir to enum. */
infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of file's volume. */
infoPB.dirInfo.ioDrDirID = spec.parID; /* ID of dir. */
infoPB.dirInfo.ioFDirIndex = 0; /* file (not parent) info. */
Jul 28, 2002
Jul 28, 2002
574
BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, NULL);
Apr 5, 2002
Apr 5, 2002
575
576
577
578
579
580
581
582
if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) == 0)
BAIL_MACRO(ERR_NOT_A_DIR, NULL);
dirID = infoPB.dirInfo.ioDrDirID;
max = infoPB.dirInfo.ioDrNmFls;
for (i = 1; i <= max; i++)
Apr 4, 2002
Apr 4, 2002
583
{
Sep 29, 2004
Sep 29, 2004
584
size_t size;
Apr 6, 2002
Apr 6, 2002
585
586
587
588
FSSpec aliasspec;
Boolean alias = 0;
Boolean folder = 0;
Apr 4, 2002
Apr 4, 2002
589
590
memset(&infoPB, '\0', sizeof (CInfoPBRec));
str255[0] = 0;
Apr 5, 2002
Apr 5, 2002
591
592
593
594
infoPB.dirInfo.ioNamePtr = str255; /* store name in here. */
infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of dir's volume. */
infoPB.dirInfo.ioDrDirID = dirID; /* ID of dir. */
infoPB.dirInfo.ioFDirIndex = i; /* next file's info. */
Apr 4, 2002
Apr 4, 2002
595
if (PBGetCatInfoSync(&infoPB) != noErr)
Apr 5, 2002
Apr 5, 2002
596
continue; /* skip this file. Oh well. */
Apr 4, 2002
Apr 4, 2002
597
Apr 6, 2002
Apr 6, 2002
598
599
600
601
602
603
604
605
606
607
if (FSMakeFSSpec(spec.vRefNum, dirID, str255, &aliasspec) != noErr)
continue; /* skip it. */
if (IsAliasFile(&aliasspec, &alias, &folder) != noErr)
continue; /* skip it. */
if ((alias) && (omitSymLinks))
continue;
/* still here? Add it to the list. */
Sep 29, 2004
Sep 29, 2004
608
609
610
size = (size_t) str255[0]; /* (convert to ASCIZ string...) */
memmove(&str255[0], &str255[1], size);
str255[size] = '\0';
Sep 18, 2005
Sep 18, 2005
611
callback(callbackdata, origdir, (const char *) str255);
Apr 5, 2002
Apr 5, 2002
612
} /* for */
Mar 14, 2005
Mar 14, 2005
613
614
return(1);
Sep 29, 2004
Sep 29, 2004
615
} /* macClassicEnumerateFiles */
Apr 4, 2002
Apr 4, 2002
616
Sep 29, 2004
Sep 29, 2004
617
618
619
void __PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
620
621
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
622
623
void *callbackdata)
{
Sep 18, 2005
Sep 18, 2005
624
625
macClassicEnumerateFiles(dirname, omitSymLinks, callback,
origdir, callbackdata);
626
627
628
629
630
} /* __PHYSFS_platformEnumerateFiles */
char *__PHYSFS_platformCurrentDir(void)
{
Apr 3, 2002
Apr 3, 2002
631
/*
Mar 11, 2007
Mar 11, 2007
632
* I don't think Mac OS has a concept of "current directory", beyond
Apr 3, 2002
Apr 3, 2002
633
634
635
636
637
* what is grafted on by a given standard C library implementation,
* so just return the base dir.
* We don't use this for anything crucial at the moment anyhow.
*/
return(__PHYSFS_platformCalcBaseDir(NULL));
638
639
640
641
642
} /* __PHYSFS_platformCurrentDir */
char *__PHYSFS_platformRealPath(const char *path)
{
Apr 6, 2002
Apr 6, 2002
643
644
645
646
647
648
649
650
/*
* fnameToFSSpec() will resolve any symlinks to get to the real
* file's FSSpec, which, when converted, will contain the real
* direct path to a given file. convFSSpecToPath() mallocs a
* return value buffer.
*/
FSSpec spec;
Jul 25, 2002
Jul 25, 2002
651
BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, NULL);
Apr 6, 2002
Apr 6, 2002
652
return(convFSSpecToPath(&spec, 1));
653
654
655
656
657
} /* __PHYSFS_platformRealPath */
int __PHYSFS_platformMkDir(const char *path)
{
Apr 5, 2002
Apr 5, 2002
658
659
660
661
662
SInt32 val = 0;
FSSpec spec;
OSErr err = fnameToFSSpec(path, &spec);
BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
Jul 25, 2002
Jul 25, 2002
663
BAIL_IF_MACRO(err != fnfErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
664
665
err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
Jul 28, 2002
Jul 28, 2002
666
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
667
return(1);
668
669
670
} /* __PHYSFS_platformMkDir */
Apr 5, 2002
Apr 5, 2002
671
672
673
674
675
676
static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
{
int created = 0;
SInt16 *retval = NULL;
FSSpec spec;
OSErr err = fnameToFSSpec(fname, &spec);
Jul 25, 2002
Jul 25, 2002
677
BAIL_IF_MACRO((err != noErr) && (err != fnfErr), NULL, NULL);
Apr 5, 2002
Apr 5, 2002
678
679
if (err == fnfErr)
{
Jul 23, 2002
Jul 23, 2002
680
BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
Apr 5, 2002
Apr 5, 2002
681
682
err = HCreate(spec.vRefNum, spec.parID, spec.name,
procInfo.processSignature, 'BINA');
Jul 28, 2002
Jul 28, 2002
683
BAIL_IF_MACRO(oserr(err) != noErr, NULL, NULL);
Apr 5, 2002
Apr 5, 2002
684
685
686
created = 1;
} /* if */
Mar 14, 2005
Mar 14, 2005
687
retval = (SInt16 *) allocator.Malloc(sizeof (SInt16));
Apr 5, 2002
Apr 5, 2002
688
689
690
691
692
693
694
if (retval == NULL)
{
if (created)
HDelete(spec.vRefNum, spec.parID, spec.name);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
Jan 31, 2003
Jan 31, 2003
695
err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
Jul 28, 2002
Jul 28, 2002
696
if (oserr(err) != noErr)
Apr 5, 2002
Apr 5, 2002
697
{
Mar 14, 2005
Mar 14, 2005
698
allocator.Free(retval);
Apr 5, 2002
Apr 5, 2002
699
700
if (created)
HDelete(spec.vRefNum, spec.parID, spec.name);
Jul 28, 2002
Jul 28, 2002
701
return(NULL);
Apr 5, 2002
Apr 5, 2002
702
703
704
705
706
707
} /* if */
return(retval);
} /* macDoOpen */
708
709
void *__PHYSFS_platformOpenRead(const char *filename)
{
Apr 5, 2002
Apr 5, 2002
710
711
712
SInt16 *retval = macDoOpen(filename, fsRdPerm, 0);
if (retval != NULL) /* got a file; seek to start. */
{
Jul 28, 2002
Jul 28, 2002
713
if (oserr(SetFPos(*retval, fsFromStart, 0)) != noErr)
Apr 5, 2002
Apr 5, 2002
714
715
{
FSClose(*retval);
Jul 28, 2002
Jul 28, 2002
716
return(NULL);
Apr 5, 2002
Apr 5, 2002
717
718
719
720
} /* if */
} /* if */
return((void *) retval);
721
722
723
724
725
} /* __PHYSFS_platformOpenRead */
void *__PHYSFS_platformOpenWrite(const char *filename)
{
Apr 5, 2002
Apr 5, 2002
726
727
728
SInt16 *retval = macDoOpen(filename, fsRdWrPerm, 1);
if (retval != NULL) /* got a file; truncate it. */
{
Jul 28, 2002
Jul 28, 2002
729
730
if ((oserr(SetEOF(*retval, 0)) != noErr) ||
(oserr(SetFPos(*retval, fsFromStart, 0)) != noErr))
Apr 5, 2002
Apr 5, 2002
731
732
{
FSClose(*retval);
Jul 28, 2002
Jul 28, 2002
733
return(NULL);
Apr 5, 2002
Apr 5, 2002
734
735
736
737
} /* if */
} /* if */
return((void *) retval);
738
739
740
741
742
} /* __PHYSFS_platformOpenWrite */
void *__PHYSFS_platformOpenAppend(const char *filename)
{
Apr 5, 2002
Apr 5, 2002
743
744
745
SInt16 *retval = macDoOpen(filename, fsRdWrPerm, 1);
if (retval != NULL) /* got a file; seek to end. */
{
Jul 28, 2002
Jul 28, 2002
746
if (oserr(SetFPos(*retval, fsFromLEOF, 0)) != noErr)
Apr 5, 2002
Apr 5, 2002
747
748
{
FSClose(*retval);
Jul 28, 2002
Jul 28, 2002
749
return(NULL);
Apr 5, 2002
Apr 5, 2002
750
751
752
753
} /* if */
} /* if */
return(retval);
754
755
756
757
758
759
} /* __PHYSFS_platformOpenAppend */
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
Apr 5, 2002
Apr 5, 2002
760
SInt16 ref = *((SInt16 *) opaque);
Mar 16, 2005
Mar 16, 2005
761
SInt32 br = size*count;
Apr 5, 2002
Apr 5, 2002
762
Mar 16, 2005
Mar 16, 2005
763
764
BAIL_IF_MACRO(oserr(FSRead(ref, &br, buffer)) != noErr, NULL, br/size);
BAIL_IF_MACRO(br != size*count, NULL, br/size); /* !!! FIXME: seek back if only read part of an object! */
Apr 5, 2002
Apr 5, 2002
765
766
return(count);
767
768
769
770
771
772
} /* __PHYSFS_platformRead */
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
Apr 5, 2002
Apr 5, 2002
773
SInt16 ref = *((SInt16 *) opaque);
Mar 16, 2005
Mar 16, 2005
774
SInt32 bw = size*count;
Apr 5, 2002
Apr 5, 2002
775
Mar 16, 2005
Mar 16, 2005
776
777
BAIL_IF_MACRO(oserr(FSWrite(ref, &bw, buffer)) != noErr, NULL, bw/size);
BAIL_IF_MACRO(bw != size*count, NULL, bw/size); /* !!! FIXME: seek back if only wrote part of an object! */
Apr 5, 2002
Apr 5, 2002
778
779
return(count);
780
781
782
783
784
} /* __PHYSFS_platformWrite */
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
{
Apr 5, 2002
Apr 5, 2002
785
786
SInt16 ref = *((SInt16 *) opaque);
OSErr err = SetFPos(ref, fsFromStart, (SInt32) pos);
Jul 28, 2002
Jul 28, 2002
787
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
788
return(1);
789
790
791
792
793
} /* __PHYSFS_platformSeek */
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
Apr 5, 2002
Apr 5, 2002
794
795
SInt16 ref = *((SInt16 *) opaque);
SInt32 curPos;
Jul 28, 2002
Jul 28, 2002
796
BAIL_IF_MACRO(oserr(GetFPos(ref, &curPos)) != noErr, NULL, -1);
Apr 5, 2002
Apr 5, 2002
797
return((PHYSFS_sint64) curPos);
798
799
800
801
802
} /* __PHYSFS_platformTell */
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
{
Apr 5, 2002
Apr 5, 2002
803
804
SInt16 ref = *((SInt16 *) opaque);
SInt32 eofPos;
Jul 28, 2002
Jul 28, 2002
805
BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, -1);
Apr 5, 2002
Apr 5, 2002
806
return((PHYSFS_sint64) eofPos);
807
808
809
810
811
} /* __PHYSFS_platformFileLength */
int __PHYSFS_platformEOF(void *opaque)
{
Apr 5, 2002
Apr 5, 2002
812
813
SInt16 ref = *((SInt16 *) opaque);
SInt32 eofPos, curPos;
Jul 28, 2002
Jul 28, 2002
814
815
BAIL_IF_MACRO(oserr(GetEOF(ref, &eofPos)) != noErr, NULL, 1);
BAIL_IF_MACRO(oserr(GetFPos(ref, &curPos)) != noErr, NULL, 1);
Apr 5, 2002
Apr 5, 2002
816
return(curPos >= eofPos);
817
818
819
820
821
} /* __PHYSFS_platformEOF */
int __PHYSFS_platformFlush(void *opaque)
{
Apr 5, 2002
Apr 5, 2002
822
823
824
825
SInt16 ref = *((SInt16 *) opaque);
ParamBlockRec pb;
memset(&pb, '\0', sizeof (ParamBlockRec));
pb.ioParam.ioRefNum = ref;
Jul 28, 2002
Jul 28, 2002
826
BAIL_IF_MACRO(oserr(PBFlushFileSync(&pb)) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
827
return(1);
828
829
830
831
832
} /* __PHYSFS_platformFlush */
int __PHYSFS_platformClose(void *opaque)
{
Apr 5, 2002
Apr 5, 2002
833
834
835
SInt16 ref = *((SInt16 *) opaque);
SInt16 vRefNum;
Str63 volName;
Jul 28, 2002
Jul 28, 2002
836
int flushVol = 0;
Apr 5, 2002
Apr 5, 2002
837
Jul 28, 2002
Jul 28, 2002
838
839
840
841
842
843
844
845
846
847
if (GetVRefNum(ref, &vRefNum) == noErr)
{
HParamBlockRec hpbr;
memset(&hpbr, '\0', sizeof (HParamBlockRec));
hpbr.volumeParam.ioNamePtr = volName;
hpbr.volumeParam.ioVRefNum = vRefNum;
hpbr.volumeParam.ioVolIndex = 0;
if (PBHGetVInfoSync(&hpbr) == noErr)
flushVol = 1;
} /* if */
Apr 5, 2002
Apr 5, 2002
848
Jul 28, 2002
Jul 28, 2002
849
BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
Mar 14, 2005
Mar 14, 2005
850
allocator.Free(opaque);
Apr 5, 2002
Apr 5, 2002
851
Jul 28, 2002
Jul 28, 2002
852
853
854
if (flushVol)
FlushVol(volName, vRefNum); /* update catalog info, etc. */
Apr 5, 2002
Apr 5, 2002
855
return(1);
856
857
858
859
860
} /* __PHYSFS_platformClose */
int __PHYSFS_platformDelete(const char *path)
{
Apr 5, 2002
Apr 5, 2002
861
862
FSSpec spec;
OSErr err;
Jul 25, 2002
Jul 25, 2002
863
BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
864
err = HDelete(spec.vRefNum, spec.parID, spec.name);
Jul 28, 2002
Jul 28, 2002
865
BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0);
Apr 5, 2002
Apr 5, 2002
866
return(1);
867
868
869
870
871
} /* __PHYSFS_platformDelete */
void *__PHYSFS_platformCreateMutex(void)
{
Mar 11, 2007
Mar 11, 2007
872
return((void *) 0x0001); /* no mutexes on Mac OS classic. */
873
874
875
876
877
} /* __PHYSFS_platformCreateMutex */
void __PHYSFS_platformDestroyMutex(void *mutex)
{
Mar 11, 2007
Mar 11, 2007
878
/* no mutexes on Mac OS classic. */
879
880
881
882
883
} /* __PHYSFS_platformDestroyMutex */
int __PHYSFS_platformGrabMutex(void *mutex)
{
Mar 11, 2007
Mar 11, 2007
884
return(1); /* no mutexes on Mac OS classic. */
885
886
887
888
889
} /* __PHYSFS_platformGrabMutex */
void __PHYSFS_platformReleaseMutex(void *mutex)
{
Mar 11, 2007
Mar 11, 2007
890
/* no mutexes on Mac OS classic. */
891
892
} /* __PHYSFS_platformReleaseMutex */
May 25, 2002
May 25, 2002
893
894
895
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
May 25, 2002
May 25, 2002
896
897
898
899
FSSpec spec;
CInfoPBRec infoPB;
UInt32 modDate;
Jul 25, 2002
Jul 25, 2002
900
901
if (fnameToFSSpec(fname, &spec) != noErr)
return(-1); /* fnameToFSSpec() sets physfs error message. */
May 25, 2002
May 25, 2002
902
903
904
905
906
907
memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = spec.name;
infoPB.dirInfo.ioVRefNum = spec.vRefNum;
infoPB.dirInfo.ioDrDirID = spec.parID;
infoPB.dirInfo.ioFDirIndex = 0;
Jul 28, 2002
Jul 28, 2002
908
BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, -1);
May 25, 2002
May 25, 2002
909
910
911
912
modDate = ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) ?
infoPB.dirInfo.ioDrMdDat : infoPB.hFileInfo.ioFlMdDat;
Mar 11, 2007
Mar 11, 2007
913
/* epoch is different on Mac OS. They use Jan 1, 1904, apparently. */
May 25, 2002
May 25, 2002
914
915
916
917
/* subtract seconds between those epochs, counting leap years. */
modDate -= 2082844800;
return((PHYSFS_sint64) modDate);
May 25, 2002
May 25, 2002
918
919
} /* __PHYSFS_platformGetLastModTime */
Mar 14, 2005
Mar 14, 2005
920
921
922
923
924
925
926
927
928
929
930
931
932
933
/* !!! FIXME: Don't use C runtime for allocators? */
int __PHYSFS_platformAllocatorInit(void)
{
return(1); /* always succeeds. */
} /* __PHYSFS_platformAllocatorInit */
void __PHYSFS_platformAllocatorDeinit(void)
{
/* no-op */
} /* __PHYSFS_platformAllocatorInit */
Sep 6, 2005
Sep 6, 2005
934
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s)
Mar 14, 2005
Mar 14, 2005
935
{
Jan 1, 2006
Jan 1, 2006
936
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
Mar 14, 2005
Mar 14, 2005
937
#undef malloc
Sep 6, 2005
Sep 6, 2005
938
return(malloc((size_t) s));
Mar 14, 2005
Mar 14, 2005
939
940
941
} /* __PHYSFS_platformMalloc */
Sep 6, 2005
Sep 6, 2005
942
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s)
Mar 14, 2005
Mar 14, 2005
943
{
Jan 1, 2006
Jan 1, 2006
944
BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
Mar 14, 2005
Mar 14, 2005
945
#undef realloc
Sep 6, 2005
Sep 6, 2005
946
return(realloc(ptr, (size_t) s));
Mar 14, 2005
Mar 14, 2005
947
948
949
950
951
952
953
954
955
} /* __PHYSFS_platformRealloc */
void __PHYSFS_platformAllocatorFree(void *ptr)
{
#undef free
free(ptr);
} /* __PHYSFS_platformAllocatorFree */
Mar 11, 2007
Mar 11, 2007
956
957
#endif /* PHYSFS_PLATFORM_MACCLASSIC */
Apr 5, 2002
Apr 5, 2002
958
/* end of macclassic.c ... */