author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 23 Jul 2005 22:04:23 +0000 | |
branch | stable-1.0 |
changeset 720 | 31037fbc5dd8 |
parent 570 | b331437b9ec0 |
child 657 | dad3b5c307a9 |
permissions | -rw-r--r-- |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* Unix support routines for PhysicsFS. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* Please see the file LICENSE in the source's root directory. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* This file written by Ryan C. Gordon. |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
*/ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
|
214
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
9 |
#if HAVE_CONFIG_H |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
10 |
# include <config.h> |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
11 |
#endif |
19846c18071b
Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents:
191
diff
changeset
|
12 |
|
327
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
316
diff
changeset
|
13 |
/* BeOS uses beos.cpp and posix.c ... Cygwin and such use win32.c ... */ |
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
316
diff
changeset
|
14 |
#if ((!defined __BEOS__) && (!defined WIN32)) |
310
f8bca4a93fd5
Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
273
diff
changeset
|
15 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
#include <stdio.h> |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
#include <stdlib.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
18 |
#include <string.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
19 |
#include <ctype.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
20 |
#include <unistd.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
21 |
#include <sys/types.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
22 |
#include <pwd.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
23 |
#include <sys/stat.h> |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
24 |
#include <sys/param.h> |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
25 |
#include <dirent.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
26 |
#include <time.h> |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
27 |
#include <errno.h> |
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
28 |
#include <sys/mount.h> |
188 | 29 |
|
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
30 |
#ifndef PHYSFS_DARWIN |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
31 |
# if defined(__MACH__) && defined(__APPLE__) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
32 |
# define PHYSFS_DARWIN 1 |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
33 |
# include <CoreFoundation/CoreFoundation.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
34 |
# include <CoreServices/CoreServices.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
35 |
# include <IOKit/IOKitLib.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
36 |
# include <IOKit/storage/IOMedia.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
37 |
# include <IOKit/storage/IOCDMedia.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
38 |
# include <IOKit/storage/IODVDMedia.h> |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
39 |
# endif |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
40 |
#endif |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
41 |
|
390
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
42 |
#if (!defined PHYSFS_NO_PTHREADS_SUPPORT) |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
43 |
#include <pthread.h> |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
44 |
#endif |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
45 |
|
351
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
46 |
#ifdef PHYSFS_HAVE_SYS_UCRED_H |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
47 |
# ifdef PHYSFS_HAVE_MNTENT_H |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
48 |
# undef PHYSFS_HAVE_MNTENT_H /* don't do both... */ |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
49 |
# endif |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
50 |
# include <sys/ucred.h> |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
51 |
#endif |
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
52 |
|
bc4fa7896225
Generalized CD-ROM routine selection.
Ryan C. Gordon <icculus@icculus.org>
parents:
347
diff
changeset
|
53 |
#ifdef PHYSFS_HAVE_MNTENT_H |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
54 |
#include <mntent.h> |
188 | 55 |
#endif |
56 |
||
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
#define __PHYSICSFS_INTERNAL__ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
#include "physfs_internal.h" |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
const char *__PHYSFS_platformDirSeparator = "/"; |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
63 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
64 |
int __PHYSFS_platformInit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
65 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
66 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
67 |
} /* __PHYSFS_platformInit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
68 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
69 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
70 |
int __PHYSFS_platformDeinit(void) |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
71 |
{ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
72 |
return(1); /* always succeed. */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
73 |
} /* __PHYSFS_platformDeinit */ |
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
74 |
|
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
75 |
|
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
76 |
#ifdef PHYSFS_NO_CDROM_SUPPORT |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
77 |
|
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
78 |
/* Stub version for platforms without CD-ROM support. */ |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
79 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
80 |
{ |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
81 |
char **retval = (char **) malloc(sizeof (char *)); |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
82 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
83 |
*retval = NULL; |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
84 |
return(retval); |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
85 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
86 |
|
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
87 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
88 |
#elif (defined PHYSFS_DARWIN) /* "Big Nasty." */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
89 |
/* |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
90 |
* Code based on sample from Apple Developer Connection: |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
91 |
* http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
92 |
*/ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
93 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
94 |
static int darwinIsWholeMedia(io_service_t service) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
95 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
96 |
int retval = 0; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
97 |
CFTypeRef wholeMedia; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
98 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
99 |
if (!IOObjectConformsTo(service, kIOMediaClass)) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
100 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
101 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
102 |
wholeMedia = IORegistryEntryCreateCFProperty(service, |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
103 |
CFSTR(kIOMediaWholeKey), |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
104 |
kCFAllocatorDefault, 0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
105 |
if (wholeMedia == NULL) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
106 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
107 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
108 |
retval = CFBooleanGetValue(wholeMedia); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
109 |
CFRelease(wholeMedia); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
110 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
111 |
return retval; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
112 |
} /* darwinIsWholeMedia */ |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
113 |
|
130
2deec3eb7430
Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents:
117
diff
changeset
|
114 |
|
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
115 |
static int darwinIsMountedDisc(char *bsdName, mach_port_t masterPort) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
116 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
117 |
int retval = 0; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
118 |
CFMutableDictionaryRef matchingDict; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
119 |
kern_return_t rc; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
120 |
io_iterator_t iter; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
121 |
io_service_t service; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
122 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
123 |
if ((matchingDict = IOBSDNameMatching(masterPort, 0, bsdName)) == NULL) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
124 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
125 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
126 |
rc = IOServiceGetMatchingServices(masterPort, matchingDict, &iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
127 |
if ((rc != KERN_SUCCESS) || (!iter)) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
128 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
129 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
130 |
service = IOIteratorNext(iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
131 |
IOObjectRelease(iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
132 |
if (!service) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
133 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
134 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
135 |
rc = IORegistryEntryCreateIterator(service, kIOServicePlane, |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
136 |
kIORegistryIterateRecursively | kIORegistryIterateParents, &iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
137 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
138 |
if (!iter) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
139 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
140 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
141 |
if (rc != KERN_SUCCESS) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
142 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
143 |
IOObjectRelease(iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
144 |
return(0); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
145 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
146 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
147 |
IOObjectRetain(service); /* add an extra object reference... */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
148 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
149 |
do |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
150 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
151 |
if (darwinIsWholeMedia(service)) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
152 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
153 |
if ( (IOObjectConformsTo(service, kIOCDMediaClass)) || |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
154 |
(IOObjectConformsTo(service, kIODVDMediaClass)) ) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
155 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
156 |
retval = 1; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
157 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
158 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
159 |
IOObjectRelease(service); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
160 |
} while ((service = IOIteratorNext(iter)) && (!retval)); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
161 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
162 |
IOObjectRelease(iter); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
163 |
IOObjectRelease(service); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
164 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
165 |
return(retval); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
166 |
} /* darwinIsMountedDisc */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
167 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
168 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
169 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
170 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
171 |
const char *devPrefix = "/dev/"; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
172 |
int prefixLen = strlen(devPrefix); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
173 |
mach_port_t masterPort = 0; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
174 |
char **retval = (char **) malloc(sizeof (char *)); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
175 |
int cd_count = 1; /* We count the NULL entry. */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
176 |
struct statfs *mntbufp; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
177 |
int i, mounts; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
178 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
179 |
retval[0] = NULL; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
180 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
181 |
if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
182 |
return(retval); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
183 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
184 |
mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
185 |
for (i = 0; i < mounts; i++) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
186 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
187 |
char *dev = mntbufp[i].f_mntfromname; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
188 |
char *mnt = mntbufp[i].f_mntonname; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
189 |
if (strncmp(dev, devPrefix, prefixLen) != 0) /* a virtual device? */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
190 |
continue; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
191 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
192 |
dev += prefixLen; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
193 |
if (darwinIsMountedDisc(dev, masterPort)) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
194 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
195 |
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1)); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
196 |
if (tmp) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
197 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
198 |
retval = tmp; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
199 |
retval[cd_count - 1] = (char *) malloc(strlen(mnt) + 1); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
200 |
if (retval[cd_count - 1]) |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
201 |
{ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
202 |
strcpy(retval[cd_count - 1], mnt); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
203 |
cd_count++; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
204 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
205 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
206 |
} /* if */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
207 |
} /* for */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
208 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
209 |
retval[cd_count - 1] = NULL; |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
210 |
return(retval); |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
211 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
212 |
|
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
213 |
#elif (defined PHYSFS_HAVE_SYS_UCRED_H) |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
214 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
215 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
216 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
217 |
char **retval = (char **) malloc(sizeof (char *)); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
218 |
int cd_count = 1; /* We count the NULL entry. */ |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
219 |
struct statfs *mntbufp = NULL; |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
220 |
int mounts; |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
221 |
int i; |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
222 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
223 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
224 |
|
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
225 |
mounts = getmntinfo(&mntbufp, MNT_WAIT); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
226 |
|
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
227 |
for (i = 0; i < mounts; i++) |
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
228 |
{ |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
229 |
int add_it = 0; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
230 |
|
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
231 |
if (strcmp(mntbufp[i].f_fstypename, "iso9660") == 0) |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
232 |
add_it = 1; |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
233 |
else if (strcmp( mntbufp[i].f_fstypename, "cd9660") == 0) |
191 | 234 |
add_it = 1; |
225 | 235 |
|
236 |
/* add other mount types here */ |
|
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
237 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
238 |
if (add_it) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
239 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
240 |
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1)); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
241 |
if (tmp) |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
242 |
{ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
243 |
retval = tmp; |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
244 |
retval[cd_count - 1] = (char *) |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
245 |
malloc(strlen(mntbufp[i].f_mntonname) + 1); |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
246 |
if (retval[cd_count - 1]) |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
247 |
{ |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
248 |
strcpy(retval[cd_count - 1], mntbufp[i].f_mntonname); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
249 |
cd_count++; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
250 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
251 |
} /* if */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
252 |
} /* if */ |
381
b65d27fdc8a9
Can now disable CD-ROM code on Unix systems at build time if need be. The
Ryan C. Gordon <icculus@icculus.org>
parents:
351
diff
changeset
|
253 |
} /* for */ |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
254 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
255 |
retval[cd_count - 1] = NULL; |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
256 |
return(retval); |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
257 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
258 |
|
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
259 |
#elif (defined PHYSFS_HAVE_MNTENT_H) |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
260 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
{ |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
263 |
char **retval = (char **) malloc(sizeof (char *)); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
264 |
int cd_count = 1; /* We count the NULL entry. */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
265 |
FILE *mounts = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
266 |
struct mntent *ent = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
267 |
|
171
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
268 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
0d92d6358410
Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
145
diff
changeset
|
269 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
270 |
*retval = NULL; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
271 |
mounts = setmntent("/etc/mtab", "r"); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
272 |
BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, retval); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
273 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
274 |
while ( (ent = getmntent(mounts)) != NULL ) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
275 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
276 |
int add_it = 0; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
277 |
if (strcmp(ent->mnt_type, "iso9660") == 0) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
278 |
add_it = 1; |
225 | 279 |
|
280 |
/* add other mount types here */ |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
281 |
|
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
282 |
if (add_it) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
283 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
284 |
char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1)); |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
285 |
if (tmp) |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
286 |
{ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
287 |
retval = tmp; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
288 |
retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1); |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
289 |
if (retval[cd_count - 1]) |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
290 |
{ |
316
29a4d12d1dc6
Fixed buffer overflow in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
291 |
strcpy(retval[cd_count - 1], ent->mnt_dir); |
63
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
292 |
cd_count++; |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
293 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
294 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
295 |
} /* if */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
296 |
} /* while */ |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
297 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
298 |
endmntent(mounts); |
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
299 |
|
cb9a4714b844
Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents:
41
diff
changeset
|
300 |
retval[cd_count - 1] = NULL; |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
301 |
return(retval); |
117
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
302 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
303 |
|
55ae10d7f2a9
Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents:
115
diff
changeset
|
304 |
#endif |
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
|
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
|
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
307 |
/* this is in posix.c ... */ |
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
308 |
extern char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname); |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
309 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
310 |
|
225 | 311 |
/* |
312 |
* See where program (bin) resides in the $PATH specified by (envr). |
|
313 |
* returns a copy of the first element in envr that contains it, or NULL |
|
314 |
* if it doesn't exist or there were other problems. PHYSFS_SetError() is |
|
315 |
* called if we have a problem. |
|
316 |
* |
|
317 |
* (envr) will be scribbled over, and you are expected to free() the |
|
318 |
* return value when you're done with it. |
|
319 |
*/ |
|
320 |
static char *findBinaryInPath(const char *bin, char *envr) |
|
321 |
{ |
|
322 |
size_t alloc_size = 0; |
|
323 |
char *exe = NULL; |
|
324 |
char *start = envr; |
|
325 |
char *ptr; |
|
326 |
||
327 |
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL); |
|
328 |
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL); |
|
329 |
||
330 |
do |
|
331 |
{ |
|
332 |
size_t size; |
|
333 |
ptr = strchr(start, ':'); /* find next $PATH separator. */ |
|
334 |
if (ptr) |
|
335 |
*ptr = '\0'; |
|
336 |
||
337 |
size = strlen(start) + strlen(bin) + 2; |
|
338 |
if (size > alloc_size) |
|
339 |
{ |
|
340 |
char *x = (char *) realloc(exe, size); |
|
341 |
if (x == NULL) |
|
342 |
{ |
|
343 |
if (exe != NULL) |
|
344 |
free(exe); |
|
345 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
|
346 |
} /* if */ |
|
347 |
||
348 |
alloc_size = size; |
|
349 |
exe = x; |
|
350 |
} /* if */ |
|
351 |
||
352 |
/* build full binary path... */ |
|
353 |
strcpy(exe, start); |
|
505
c7f7f234a156
Minor fix for odd PATH entries.
Ryan C. Gordon <icculus@icculus.org>
parents:
452
diff
changeset
|
354 |
if ((exe[0] == '\0') || (exe[strlen(exe) - 1] != '/')) |
225 | 355 |
strcat(exe, "/"); |
356 |
strcat(exe, bin); |
|
357 |
||
358 |
if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */ |
|
359 |
{ |
|
360 |
strcpy(exe, start); /* i'm lazy. piss off. */ |
|
361 |
return(exe); |
|
362 |
} /* if */ |
|
363 |
||
364 |
start = ptr + 1; /* start points to beginning of next element. */ |
|
365 |
} while (ptr != NULL); |
|
366 |
||
367 |
if (exe != NULL) |
|
368 |
free(exe); |
|
369 |
||
370 |
return(NULL); /* doesn't exist in path. */ |
|
371 |
} /* findBinaryInPath */ |
|
372 |
||
373 |
||
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
374 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
375 |
{ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
376 |
/* If there isn't a path on argv0, then look through the $PATH for it. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
377 |
|
225 | 378 |
char *retval; |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
379 |
char *envr; |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
380 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
381 |
if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
382 |
return(NULL); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
383 |
|
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
384 |
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH"); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
385 |
BAIL_IF_MACRO(!envr, NULL, NULL); |
225 | 386 |
retval = findBinaryInPath(argv0, envr); |
23
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
387 |
free(envr); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
388 |
return(retval); |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
389 |
} /* __PHYSFS_platformCalcBaseDir */ |
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
390 |
|
bd6ba9c8717c
Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents:
20
diff
changeset
|
391 |
|
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
392 |
/* Much like my college days, try to sleep for 10 milliseconds at a time... */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
393 |
void __PHYSFS_platformTimeslice(void) |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
394 |
{ |
115
c0671785777b
Changed timeslice implementation to use something more portable (thanks to
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
395 |
usleep( 10 * 1000 ); /* don't care if it fails. */ |
20
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
396 |
} /* __PHYSFS_platformTimeslice */ |
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
397 |
|
efdde0d21521
Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents:
17
diff
changeset
|
398 |
|
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
399 |
#if PHYSFS_DARWIN |
520
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
400 |
/* |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
401 |
* This function is only for OSX. The problem is that Apple's applications |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
402 |
* can actually be directory structures with the actual executable nested |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
403 |
* several levels down. PhysFS computes the base directory from the Unix |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
404 |
* executable, but this may not be the correct directory. Apple tries to |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
405 |
* hide everything from the user, so from Finder, the user never sees the |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
406 |
* Unix executable, and the directory package (bundle) is considered the |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
407 |
* "executable". This means that the correct base directory is at the |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
408 |
* level where the directory structure starts. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
409 |
* A typical bundle seems to look like this: |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
410 |
* MyApp.app/ <-- top level...this is what the user sees in Finder |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
411 |
* Contents/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
412 |
* MacOS/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
413 |
* MyApp <-- the actual executable |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
414 |
* |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
415 |
* Since anything below the app folder is considered hidden, most |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
416 |
* application files need to be at the top level if you intend to |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
417 |
* write portable software. Thus if the application resides in: |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
418 |
* /Applications/MyProgram |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
419 |
* and the executable is the bundle MyApp.app, |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
420 |
* PhysFS computes the following as the base directory: |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
421 |
* /Applications/MyProgram/MyApp.app/Contents/MacOS/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
422 |
* We need to strip off the MyApp.app/Contents/MacOS/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
423 |
* |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
424 |
* However, there are corner cases. OSX applications can be traditional |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
425 |
* Unix executables without the bundle. Also, it is not entirely clear |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
426 |
* to me what kinds of permutations bundle structures can have. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
427 |
* |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
428 |
* For now, this is a temporary hack until a better solution |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
429 |
* can be made. This function will try to find a "/Contents/MacOS" |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
430 |
* inside the path. If it succeeds, then the path will be truncated |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
431 |
* to correct the directory. If it is not found, the path will be |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
432 |
* left alone and will presume it is a traditional Unix execuatable. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
433 |
* Most programs also include the .app extention in the top level |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
434 |
* folder, but it doesn't seem to be a requirement (Acrobat doesn't |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
435 |
* have it). MacOS looks like it can also be MacOSClassic. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
436 |
* This function will test for MacOS and hope it captures any |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
437 |
* other permutations. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
438 |
*/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
439 |
static void stripAppleBundle(char *path) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
440 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
441 |
char *sub_str = "/contents/macos"; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
442 |
char *found_ptr = NULL; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
443 |
char *tempbuf = NULL; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
444 |
int i; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
445 |
|
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
446 |
/* Calloc will place the \0 character in the proper place for us */ |
570
b331437b9ec0
Rewrote MacOSX/Darwin CD detection to use IOKit, for accurate results.
Ryan C. Gordon <icculus@icculus.org>
parents:
520
diff
changeset
|
447 |
/* !!! FIXME: Can we stack-allocate this? --ryan. */ |
520
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
448 |
tempbuf = (char*)calloc( (strlen(path)+1), sizeof(char) ); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
449 |
/* Unlike other Unix filesystems, HFS is case insensitive |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
450 |
* It wouldn be nice to use strcasestr, but it doesn't seem |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
451 |
* to be available in the OSX gcc library right now. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
452 |
* So we should make a lower case copy of the path to |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
453 |
* compare against |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
454 |
*/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
455 |
for(i=0; i<strlen(path); i++) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
456 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
457 |
/* convert to lower case */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
458 |
tempbuf[i] = tolower(path[i]); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
459 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
460 |
/* See if we can find "/contents/macos" in the path */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
461 |
found_ptr = strstr(tempbuf, sub_str); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
462 |
if(NULL == found_ptr) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
463 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
464 |
/* It doesn't look like a bundle so we can keep the |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
465 |
* original path. Just return */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
466 |
free(tempbuf); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
467 |
return; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
468 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
469 |
/* We have a bundle, so let's backstep character by character |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
470 |
* to erase the extra parts of the path. Quit when we hit |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
471 |
* the preceding '/' character. |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
472 |
*/ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
473 |
for(i=strlen(path)-strlen(found_ptr)-1; i>=0; i--) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
474 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
475 |
if('/' == path[i]) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
476 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
477 |
break; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
478 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
479 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
480 |
/* Safety check */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
481 |
if(i<1) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
482 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
483 |
/* This probably shouldn't happen. */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
484 |
path[0] = '\0'; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
485 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
486 |
else |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
487 |
{ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
488 |
/* Back up one more to remove trailing '/' and set the '\0' */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
489 |
path[i] = '\0'; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
490 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
491 |
free(tempbuf); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
492 |
return; |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
493 |
} |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
494 |
#endif /* defined __MACH__ && defined __APPLE__ */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
495 |
|
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
496 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
497 |
char *__PHYSFS_platformRealPath(const char *path) |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
498 |
{ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
499 |
char resolved_path[MAXPATHLEN]; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
500 |
char *retval = NULL; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
501 |
|
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
502 |
errno = 0; |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
503 |
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL); |
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
504 |
retval = (char *) malloc(strlen(resolved_path) + 1); |
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
505 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
506 |
strcpy(retval, resolved_path); |
520
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
507 |
|
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
508 |
#if defined(__MACH__) && defined(__APPLE__) |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
509 |
stripAppleBundle(retval); |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
510 |
#endif /* defined __MACH__ && defined __APPLE__ */ |
a72bbf255074
Added hack for OSX bundles, from Eric Wing.
Ryan C. Gordon <icculus@icculus.org>
parents:
505
diff
changeset
|
511 |
|
39
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
512 |
return(retval); |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
513 |
} /* __PHYSFS_platformRealPath */ |
bc29e1ee7ef6
Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents:
28
diff
changeset
|
514 |
|
69
546a95cc5591
Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
515 |
|
396
15f7ccfdd89f
Whoops; the pthread-disabling condition was flipped. Fixed.
Ryan C. Gordon <icculus@icculus.org>
parents:
392
diff
changeset
|
516 |
#if (defined PHYSFS_NO_PTHREADS_SUPPORT) |
390
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
517 |
|
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
518 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) { return(0x0001); } |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
519 |
void *__PHYSFS_platformCreateMutex(void) { return((void *) 0x0001); } |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
520 |
void __PHYSFS_platformDestroyMutex(void *mutex) {} |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
521 |
int __PHYSFS_platformGrabMutex(void *mutex) { return(1); } |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
522 |
void __PHYSFS_platformReleaseMutex(void *mutex) {} |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
523 |
|
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
524 |
#else |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
525 |
|
452
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
526 |
/* Just in case; this is a panic value. */ |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
527 |
#if ((!defined SIZEOF_INT) || (SIZEOF_INT <= 0)) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
528 |
# define SIZEOF_INT 4 |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
529 |
#endif |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
530 |
|
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
531 |
#if (SIZEOF_INT == 4) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
532 |
# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint32) (thr)) ) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
533 |
#elif (SIZEOF_INT == 2) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
534 |
# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint16) (thr)) ) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
535 |
#elif (SIZEOF_INT == 1) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
536 |
# define PHTREAD_TO_UI64(thr) ( (PHYSFS_uint64) ((PHYSFS_uint8) (thr)) ) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
537 |
#else |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
538 |
# define PHTREAD_TO_UI64(thr) ((PHYSFS_uint64) (thr)) |
89578e99ba6e
Attempt to fix pthread-to-ui64 cast issue.
Ryan C. Gordon <icculus@icculus.org>
parents:
396
diff
changeset
|
539 |
#endif |
392
bcc8e4dca868
First step towards getting __PHYSFS_platformGetThreadID() to work universally.
Ryan C. Gordon <icculus@icculus.org>
parents:
390
diff
changeset
|
540 |
|
390
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
541 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
542 |
{ |
392
bcc8e4dca868
First step towards getting __PHYSFS_platformGetThreadID() to work universally.
Ryan C. Gordon <icculus@icculus.org>
parents:
390
diff
changeset
|
543 |
return(PHTREAD_TO_UI64(pthread_self())); |
390
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
544 |
} /* __PHYSFS_platformGetThreadID */ |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
545 |
|
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
546 |
|
145
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
547 |
void *__PHYSFS_platformCreateMutex(void) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
548 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
549 |
int rc; |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
550 |
pthread_mutex_t *m = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t)); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
551 |
BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
552 |
rc = pthread_mutex_init(m, NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
553 |
if (rc != 0) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
554 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
555 |
free(m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
556 |
BAIL_MACRO(strerror(rc), NULL); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
557 |
} /* if */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
558 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
559 |
return((void *) m); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
560 |
} /* __PHYSFS_platformCreateMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
561 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
562 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
563 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
564 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
565 |
pthread_mutex_destroy((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
566 |
free(mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
567 |
} /* __PHYSFS_platformDestroyMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
568 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
569 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
570 |
int __PHYSFS_platformGrabMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
571 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
572 |
return(pthread_mutex_lock((pthread_mutex_t *) mutex) == 0); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
573 |
} /* __PHYSFS_platformGrabMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
574 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
575 |
|
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
576 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
577 |
{ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
578 |
pthread_mutex_unlock((pthread_mutex_t *) mutex); |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
579 |
} /* __PHYSFS_platformReleaseMutex */ |
d6385584f6c4
First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents:
137
diff
changeset
|
580 |
|
390
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
581 |
#endif /* !PHYSFS_NO_PTHREADS_SUPPORT */ |
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
582 |
|
6649d6caecf2
Stub code for platforms without functional pthreads.
Ryan C. Gordon <icculus@icculus.org>
parents:
381
diff
changeset
|
583 |
|
330 | 584 |
#endif /* !defined __BEOS__ && !defined WIN32 */ |
233
1b74a7df1ca6
Split some of the unix.c code out to posix.c for BeOS to use.
Ryan C. Gordon <icculus@icculus.org>
parents:
225
diff
changeset
|
585 |
|
17
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
/* end of unix.c ... */ |
7337737f5120
Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
587 |