/
os2.c
785 lines (610 loc) · 20.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
* OS/2 support routines for PhysicsFS.
*
* Please see the file LICENSE in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if (defined OS2)
#define INCL_DOSSEMAPHORES
#define INCL_DOSDATETIME
#define INCL_DOSFILEMGR
#define INCL_DOSMODULEMGR
#define INCL_DOSERRORS
20
#define INCL_DOSPROCESS
21
#define INCL_DOSDEVICES
22
23
#define INCL_DOSDEVIOCTL
#define INCL_DOSMISC
24
25
26
27
28
29
#include <os2.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
30
31
32
33
34
35
36
#include <time.h>
#include <ctype.h>
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
const char *__PHYSFS_platformDirSeparator = "\\";
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
static APIRET os2err(APIRET retval)
{
const char *err = NULL;
/*
* The ones that say "OS/2 reported" are more for PhysicsFS developer
* debugging. We give more generic messages for ones that are likely to
* fall through to an application.
*/
switch (retval)
{
case NO_ERROR: /* Don't set the PhysicsFS error message for these... */
case ERROR_INTERRUPT:
case ERROR_TIMEOUT:
break;
case ERROR_NOT_ENOUGH_MEMORY:
err = ERR_OUT_OF_MEMORY;
break;
case ERROR_FILE_NOT_FOUND:
err = "File not found";
break;
case ERROR_PATH_NOT_FOUND:
err = "Path not found";
break;
case ERROR_ACCESS_DENIED:
err = "Access denied";
break;
case ERROR_NOT_DOS_DISK:
err = "Not a DOS disk";
break;
case ERROR_SHARING_VIOLATION:
err = "Sharing violation";
break;
case ERROR_CANNOT_MAKE:
err = "Cannot make";
break;
case ERROR_DEVICE_IN_USE:
err = "Device already in use";
break;
case ERROR_OPEN_FAILED:
err = "Open failed";
break;
case ERROR_DISK_FULL:
err = "Disk is full";
break;
95
case ERROR_PIPE_BUSY:
96
97
98
99
100
101
102
103
104
105
106
107
108
err = "Pipe busy";
break;
case ERROR_SHARING_BUFFER_EXCEEDED:
err = "Sharing buffer exceeded";
break;
case ERROR_FILENAME_EXCED_RANGE:
case ERROR_META_EXPANSION_TOO_LONG:
err = "Filename too big";
break;
case ERROR_TOO_MANY_HANDLES:
109
case ERROR_TOO_MANY_OPEN_FILES:
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
case ERROR_NO_MORE_SEARCH_HANDLES:
err = "Too many open handles";
break;
case ERROR_SEEK_ON_DEVICE:
err = "Seek error"; /* Is that what this error means? */
break;
case ERROR_NEGATIVE_SEEK:
err = "Seek past start of file";
break;
case ERROR_CURRENT_DIRECTORY:
err = "Trying to delete current working directory";
break;
case ERROR_WRITE_PROTECT:
err = "Write protect error";
break;
case ERROR_WRITE_FAULT:
err = "Write fault";
break;
case ERROR_LOCK_VIOLATION:
err = "Lock violation";
break;
case ERROR_GEN_FAILURE:
err = "General failure";
break;
case ERROR_UNCERTAIN_MEDIA:
err = "Uncertain media";
break;
case ERROR_PROTECTION_VIOLATION:
err = "Protection violation";
break;
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_NAME:
case ERROR_INVALID_DRIVE:
case ERROR_INVALID_HANDLE:
case ERROR_INVALID_FUNCTION:
case ERROR_INVALID_LEVEL:
case ERROR_INVALID_CATEGORY:
case ERROR_DUPLICATE_NAME:
case ERROR_BUFFER_OVERFLOW:
case ERROR_BAD_LENGTH:
case ERROR_BAD_DRIVER_LEVEL:
case ERROR_DIRECT_ACCESS_HANDLE:
err = "OS/2 reported an invalid parameter to an API function";
break;
case ERROR_NO_VOLUME_LABEL:
err = "OS/2 reported no volume label";
break;
case ERROR_NO_MORE_FILES:
err = "OS/2 reported no more files";
break;
case ERROR_MONITORS_NOT_SUPPORTED:
err = "OS/2 reported monitors not supported";
break;
case ERROR_BROKEN_PIPE:
err = "OS/2 reported a broken pipe";
break;
case ERROR_MORE_DATA:
err = "OS/2 reported \"more data\" (?)";
break;
case ERROR_EAS_DIDNT_FIT:
err = "OS/2 reported Extended Attributes didn't fit";
break;
case ERROR_INVALID_EA_NAME:
err = "OS/2 reported an invalid Extended Attribute name";
break;
case ERROR_EA_LIST_INCONSISTENT:
err = "OS/2 reported an inconsistent Extended Attribute list";
break;
case ERROR_SEM_OWNER_DIED:
err = "OS/2 reported that semaphore owner died";
break;
case ERROR_TOO_MANY_SEM_REQUESTS:
err = "OS/2 reported too many semaphore requests";
break;
case ERROR_SEM_BUSY:
err = "OS/2 reported a blocked semaphore";
break;
case ERROR_NOT_OWNER:
err = "OS/2 reported that we used a resource we don't own.";
break;
default:
err = "OS/2 reported back with unrecognized error code";
break;
} /* switch */
if (err != NULL)
__PHYSFS_setError(err);
return(retval);
} /* os2err */
static char *baseDir = NULL;
int __PHYSFS_platformInit(void)
{
char buf[CCHMAXPATH];
APIRET rc;
231
232
PTIB ptib;
PPIB ppib;
233
PHYSFS_sint32 len;
234
235
236
assert(baseDir == NULL);
237
238
BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0);
rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
239
240
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
241
242
243
244
245
/* chop off filename, leave path. */
for (len = strlen(buf) - 1; len >= 0; len--)
{
if (buf[len] == '\\')
{
246
buf[len] = '\0';
247
248
249
250
251
252
253
break;
} /* if */
} /* for */
assert(len > 0); /* should have been an "x:\\" on the front on string. */
baseDir = (char *) malloc(len + 1);
254
BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
255
strcpy(baseDir, buf);
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
return(1); /* success. */
} /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void)
{
assert(baseDir != NULL);
free(baseDir);
baseDir = NULL;
return(1); /* success. */
} /* __PHYSFS_platformDeinit */
static int disc_is_inserted(ULONG drive)
{
int rc;
char buf[20];
DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
return(rc == NO_ERROR);
} /* is_cdrom_inserted */
static int is_cdrom_drive(ULONG drive)
{
PHYSFS_uint16 cmd = (((drive & 0xFF) << 8) | 0);
BIOSPARAMETERBLOCK bpb;
ULONG ul1, ul2;
APIRET rc;
rc = DosDevIOCtl((HFILE) -1, IOCTL_DISK,
DSK_GETDEVICEPARAMS,
&cmd, sizeof (cmd), &ul1,
291
&bpb, sizeof (bpb), &ul2);
292
293
294
295
296
/*
* !!! FIXME: Note that this tells us that the media is REMOVABLE...
* !!! FIXME: but it might not be a CD-ROM...check driver name?
*/
297
return((rc == NO_ERROR) && ((bpb.fsDeviceAttr & 0x0001) == 0));
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
} /* is_cdrom_drive */
char **__PHYSFS_platformDetectAvailableCDs(void)
{
ULONG dummy;
ULONG drivemap;
ULONG i, bit;
APIRET rc;
char **retval;
PHYSFS_uint32 cd_count = 0;
retval = (char **) malloc(sizeof (char *));
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
*retval = NULL;
rc = DosQueryCurrentDisk(&dummy, &drivemap);
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval);
/* !!! FIXME: the a, b, and c drives are almost certainly NOT cdroms... */
318
for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
{
if (drivemap & bit) /* this logical drive exists. */
{
if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
{
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
if (tmp)
{
char *str = (char *) malloc(4);
retval = tmp;
retval[cd_count - 1] = str;
if (str)
{
str[0] = ('A' + i);
str[1] = ':';
str[2] = '\\';
str[3] = '\0';
cd_count++;
} /* if */
} /* if */
} /* if */
} /* if */
} /* for */
return(retval);
} /* __PHYSFS_platformDetectAvailableCDs */
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
char *retval = (char *) malloc(strlen(baseDir) + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, baseDir); /* calculated at init time. */
return(retval);
} /* __PHYSFS_platformCalcBaseDir */
char *__PHYSFS_platformGetUserName(void)
{
return(NULL); /* (*shrug*) */
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void)
{
return(__PHYSFS_platformCalcBaseDir(NULL));
} /* __PHYSFS_platformGetUserDir */
int __PHYSFS_platformStricmp(const char *x, const char *y)
{
int ux, uy;
do
{
ux = toupper((int) *x);
uy = toupper((int) *y);
if (ux > uy)
return(1);
else if (ux < uy)
return(-1);
x++;
y++;
} while ((ux) && (uy));
return(0);
} /* __PHYSFS_platformStricmp */
int __PHYSFS_platformExists(const char *fname)
{
FILESTATUS3 fs;
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
return(os2err(rc) == NO_ERROR);
} /* __PHYSFS_platformExists */
int __PHYSFS_platformIsSymLink(const char *fname)
{
return(0); /* no symlinks in OS/2. */
} /* __PHYSFS_platformIsSymlink */
int __PHYSFS_platformIsDirectory(const char *fname)
{
FILESTATUS3 fs;
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0)
return((fs.attrFile & FILE_DIRECTORY) != 0);
} /* __PHYSFS_platformIsDirectory */
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append)
{
int len = ((prepend) ? strlen(prepend) : 0) +
((append) ? strlen(append) : 0) +
strlen(dirName) + 1;
char *retval = malloc(len);
char *p;
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
if (prepend)
strcpy(retval, prepend);
else
retval[0] = '\0';
strcat(retval, dirName);
if (append)
strcat(retval, append);
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
*p = '\\';
return(retval);
} /* __PHYSFS_platformCvtToDependent */
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks)
{
char spec[CCHMAXPATH];
LinkedStringList *retval = NULL, *p = NULL;
445
FILEFINDBUF3 fb;
446
447
448
449
450
HDIR hdir = HDIR_CREATE;
ULONG count = 1;
APIRET rc;
BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 4, ERR_OS_ERROR, NULL);
451
strcpy(spec, dirname);
452
453
454
455
456
strcat(spec, "*.*");
rc = DosFindFirst(spec, &hdir,
FILE_DIRECTORY | FILE_ARCHIVED |
FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
457
&fb, sizeof (fb), &count, FIL_STANDARD);
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
while (count == 1)
{
if (strcmp(fb.achName, ".") == 0)
continue;
if (strcmp(fb.achName, "..") == 0)
continue;
retval = __PHYSFS_addToLinkedStringList(retval, &p, fb.achName, -1);
DosFindNext(hdir, &fb, sizeof (fb), &count);
} /* while */
DosFindClose(hdir);
return(retval);
} /* __PHYSFS_platformEnumerateFiles */
char *__PHYSFS_platformCurrentDir(void)
{
char *retval;
ULONG currentDisk;
ULONG dummy;
ULONG pathSize = 0;
APIRET rc;
BYTE byte;
rc = DosQueryCurrentDisk(¤tDisk, &dummy);
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
/* The first call just tells us how much space we need for the string. */
rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
pathSize++; /* Add space for null terminator. */
retval = (char *) malloc(pathSize + 3); /* plus "x:\\" */
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
/* Actually get the string this time. */
rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
if (os2err(rc) != NO_ERROR)
{
free(retval);
return(NULL);
} /* if */
retval[0] = ('A' + (currentDisk - 1));
retval[1] = ':';
retval[2] = '\\';
return(retval);
} /* __PHYSFS_platformCurrentDir */
char *__PHYSFS_platformRealPath(const char *path)
{
char buf[CCHMAXPATH];
char *retval;
514
APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
retval = (char *) malloc(strlen(buf) + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, buf);
return(retval);
} /* __PHYSFS_platformRealPath */
int __PHYSFS_platformMkDir(const char *path)
{
return(os2err(DosCreateDir(path, NULL)) == NO_ERROR);
} /* __PHYSFS_platformMkDir */
void *__PHYSFS_platformOpenRead(const char *filename)
{
ULONG actionTaken = 0;
HFILE hfile = NULLHANDLE;
/*
* File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise
* DosQueryFileInfo() will fail if we try to get a file length, etc.
*/
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
541
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
OPEN_ACCESS_READONLY, NULL));
return((void *) hfile);
} /* __PHYSFS_platformOpenRead */
void *__PHYSFS_platformOpenWrite(const char *filename)
{
ULONG actionTaken = 0;
HFILE hfile = NULLHANDLE;
/*
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
* DosQueryFileInfo() will fail if we try to get a file length, etc.
*/
os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
560
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
561
562
563
564
565
566
567
568
569
570
OPEN_ACCESS_READWRITE, NULL));
return((void *) hfile);
} /* __PHYSFS_platformOpenWrite */
void *__PHYSFS_platformOpenAppend(const char *filename)
{
ULONG dummy = 0;
HFILE hfile = NULLHANDLE;
571
APIRET rc;
572
573
574
575
576
577
578
579
/*
* File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
* DosQueryFileInfo() will fail if we try to get a file length, etc.
*/
rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL,
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
580
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
OPEN_ACCESS_READWRITE, NULL));
if (rc == NO_ERROR)
{
if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR)
{
DosClose(hfile);
hfile = NULLHANDLE;
} /* if */
} /* if */
return((void *) hfile);
} /* __PHYSFS_platformOpenAppend */
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
HFILE hfile = (HFILE) opaque;
PHYSFS_sint64 retval;
ULONG br;
for (retval = 0; retval < count; retval++)
{
605
os2err(DosRead(hfile, buffer, size, &br));
606
607
if (br < size)
{
608
DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */
609
610
611
return(retval);
} /* if */
612
buffer = (void *) ( ((char *) buffer) + size );
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
} /* for */
return(retval);
} /* __PHYSFS_platformRead */
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
HFILE hfile = (HFILE) opaque;
PHYSFS_sint64 retval;
ULONG bw;
for (retval = 0; retval < count; retval++)
{
628
os2err(DosWrite(hfile, buffer, size, &bw));
629
630
631
632
633
634
if (bw < size)
{
DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */
return(retval);
} /* if */
635
buffer = (void *) ( ((char *) buffer) + size );
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
} /* for */
return(retval);
} /* __PHYSFS_platformWrite */
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
{
ULONG dummy;
HFILE hfile = (HFILE) opaque;
LONG dist = (LONG) pos;
/* hooray for 32-bit filesystem limits! :) */
BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0);
return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR);
} /* __PHYSFS_platformSeek */
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
ULONG pos;
HFILE hfile = (HFILE) opaque;
APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos));
BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1);
return((PHYSFS_sint64) pos);
} /* __PHYSFS_platformTell */
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
{
FILESTATUS3 fs;
HFILE hfile = (HFILE) opaque;
APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs));
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
return((PHYSFS_sint64) fs.cbFile);
} /* __PHYSFS_platformFileLength */
int __PHYSFS_platformEOF(void *opaque)
{
PHYSFS_sint64 len, pos;
len = __PHYSFS_platformFileLength(opaque);
BAIL_IF_MACRO(len == -1, NULL, 1); /* (*shrug*) */
pos = __PHYSFS_platformTell(opaque);
BAIL_IF_MACRO(pos == -1, NULL, 1); /* (*shrug*) */
return(pos >= len);
} /* __PHYSFS_platformEOF */
int __PHYSFS_platformFlush(void *opaque)
{
690
return(os2err(DosResetBuffer((HFILE) opaque) == NO_ERROR));
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
} /* __PHYSFS_platformFlush */
int __PHYSFS_platformClose(void *opaque)
{
return(os2err(DosClose((HFILE) opaque) == NO_ERROR));
} /* __PHYSFS_platformClose */
int __PHYSFS_platformDelete(const char *path)
{
if (__PHYSFS_platformIsDirectory(path))
return(os2err(DosDeleteDir(path)) == NO_ERROR);
return(os2err(DosDelete(path) == NO_ERROR));
} /* __PHYSFS_platformDelete */
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
711
PHYSFS_sint64 retval;
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
struct tm tm;
FILESTATUS3 fs;
APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
/* Convert to a format that mktime() can grok... */
tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2;
tm.tm_min = fs.ftimeLastWrite.minutes;
tm.tm_hour = fs.ftimeLastWrite.hours;
tm.tm_mday = fs.fdateLastWrite.day;
tm.tm_mon = fs.fdateLastWrite.month;
tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80;
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
tm.tm_yday = -1;
tm.tm_isdst = -1;
/* Convert to a format PhysicsFS can grok... */
retval = (PHYSFS_sint64) mktime(&tm);
BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
return(retval);
} /* __PHYSFS_platformGetLastModTime */
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
void __PHYSFS_platformTimeslice(void)
{
DosSleep(10);
} /* __PHYSFS_platformTimeslice(void) */
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
{
744
745
PTIB ptib;
PPIB ppib;
746
747
748
749
750
/*
* Allegedly, this API never fails, but we'll punt and return a
* default value (zero might as well do) if it does.
*/
751
752
BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, 0, 0);
return((PHYSFS_uint64) ptib->tib_ordinal);
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
} /* __PHYSFS_platformGetThreadID */
void *__PHYSFS_platformCreateMutex(void)
{
HMTX hmtx = NULLHANDLE;
os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0));
return((void *) hmtx);
} /* __PHYSFS_platformCreateMutex */
void __PHYSFS_platformDestroyMutex(void *mutex)
{
DosCloseMutexSem((HMTX) mutex);
} /* __PHYSFS_platformDestroyMutex */
int __PHYSFS_platformGrabMutex(void *mutex)
{
/* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */
return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR);
} /* __PHYSFS_platformGrabMutex */
void __PHYSFS_platformReleaseMutex(void *mutex)
{
DosReleaseMutexSem((HMTX) mutex);
} /* __PHYSFS_platformReleaseMutex */
#endif /* defined OS2 */
/* end of os2.c ... */