32 #define __PHYSICSFS_INTERNAL__ |
32 #define __PHYSICSFS_INTERNAL__ |
33 #include "physfs_internal.h" |
33 #include "physfs_internal.h" |
34 |
34 |
35 |
35 |
36 const char *__PHYSFS_platformDirSeparator = "/"; |
36 const char *__PHYSFS_platformDirSeparator = "/"; |
37 |
|
38 #define get_error_str(x) strerror(x) |
|
39 |
37 |
40 |
38 |
41 int __PHYSFS_platformInit(void) |
39 int __PHYSFS_platformInit(void) |
42 { |
40 { |
43 return(1); /* always succeed. */ |
41 return(1); /* always succeed. */ |
80 BDirectory directory; |
78 BDirectory directory; |
81 BEntry entry; |
79 BEntry entry; |
82 BPath path; |
80 BPath path; |
83 status_t rc; |
81 status_t rc; |
84 rc = vol.GetRootDirectory(&directory); |
82 rc = vol.GetRootDirectory(&directory); |
85 BAIL_IF_MACRO(rc < B_OK, get_error_str(rc), NULL); |
83 BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
86 rc = directory.GetEntry(&entry); |
84 rc = directory.GetEntry(&entry); |
87 BAIL_IF_MACRO(rc < B_OK, get_error_str(rc), NULL); |
85 BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
88 rc = entry.GetPath(&path); |
86 rc = entry.GetPath(&path); |
89 BAIL_IF_MACRO(rc < B_OK, get_error_str(rc), NULL); |
87 BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
90 const char *str = path.Path(); |
88 const char *str = path.Path(); |
91 BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL); /* ?! */ |
89 BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL); /* ?! */ |
92 char *retval = (char *) malloc(strlen(str) + 1); |
90 char *retval = (char *) malloc(strlen(str) + 1); |
93 BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
91 BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
94 strcpy(retval, str); |
92 strcpy(retval, str); |
186 { |
184 { |
187 /* in case there isn't a BApplication yet, we'll construct a roster. */ |
185 /* in case there isn't a BApplication yet, we'll construct a roster. */ |
188 BRoster roster; |
186 BRoster roster; |
189 app_info info; |
187 app_info info; |
190 status_t rc = roster.GetRunningAppInfo(getTeamID(), &info); |
188 status_t rc = roster.GetRunningAppInfo(getTeamID(), &info); |
191 BAIL_IF_MACRO(rc < B_OK, get_error_str(rc), NULL); |
189 BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
192 BEntry entry(&(info.ref), true); |
190 BEntry entry(&(info.ref), true); |
193 BPath path; |
191 BPath path; |
194 rc = entry.GetPath(&path); /* (path) now has binary's path. */ |
192 rc = entry.GetPath(&path); /* (path) now has binary's path. */ |
195 assert(rc == B_OK); |
193 assert(rc == B_OK); |
196 rc = path.GetParent(&path); /* chop filename, keep directory. */ |
194 rc = path.GetParent(&path); /* chop filename, keep directory. */ |
244 BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
242 BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
245 rc = create_sem(1, "PhysicsFS semaphore"); |
243 rc = create_sem(1, "PhysicsFS semaphore"); |
246 if (rc < B_OK) |
244 if (rc < B_OK) |
247 { |
245 { |
248 free(retval); |
246 free(retval); |
249 BAIL_MACRO(get_error_str(rc), NULL); |
247 BAIL_MACRO(strerror(rc), NULL); |
250 } // if |
248 } // if |
251 |
249 |
252 *retval = rc; |
250 *retval = rc; |
253 return(retval); |
251 return(retval); |
254 } /* __PHYSFS_platformCreateMutex */ |
252 } /* __PHYSFS_platformCreateMutex */ |
262 |
260 |
263 |
261 |
264 int __PHYSFS_platformGrabMutex(void *mutex) |
262 int __PHYSFS_platformGrabMutex(void *mutex) |
265 { |
263 { |
266 status_t rc = acquire_sem(*((sem_id *) mutex)); |
264 status_t rc = acquire_sem(*((sem_id *) mutex)); |
267 BAIL_IF_MACRO(rc < B_OK, get_error_str(rc), 0); |
265 BAIL_IF_MACRO(rc < B_OK, strerror(rc), 0); |
268 return(1); |
266 return(1); |
269 } /* __PHYSFS_platformGrabMutex */ |
267 } /* __PHYSFS_platformGrabMutex */ |
270 |
268 |
271 |
269 |
272 void __PHYSFS_platformReleaseMutex(void *mutex) |
270 void __PHYSFS_platformReleaseMutex(void *mutex) |