platform/unix.c
changeset 390 6649d6caecf2
parent 381 b65d27fdc8a9
child 392 bcc8e4dca868
equal deleted inserted replaced
389:b35668cd8b3e 390:6649d6caecf2
    15 
    15 
    16 #include <stdio.h>
    16 #include <stdio.h>
    17 #include <stdlib.h>
    17 #include <stdlib.h>
    18 #include <string.h>
    18 #include <string.h>
    19 #include <ctype.h>
    19 #include <ctype.h>
    20 #include <pthread.h>
       
    21 #include <unistd.h>
    20 #include <unistd.h>
    22 #include <sys/types.h>
    21 #include <sys/types.h>
    23 #include <pwd.h>
    22 #include <pwd.h>
    24 #include <sys/stat.h>
    23 #include <sys/stat.h>
    25 #include <sys/param.h>
    24 #include <sys/param.h>
    26 #include <dirent.h>
    25 #include <dirent.h>
    27 #include <time.h>
    26 #include <time.h>
    28 #include <errno.h>
    27 #include <errno.h>
    29 #include <sys/mount.h>
    28 #include <sys/mount.h>
       
    29 
       
    30 #if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
       
    31 #include <pthread.h>
       
    32 #endif
    30 
    33 
    31 #ifdef PHYSFS_HAVE_SYS_UCRED_H
    34 #ifdef PHYSFS_HAVE_SYS_UCRED_H
    32 #  ifdef PHYSFS_HAVE_MNTENT_H
    35 #  ifdef PHYSFS_HAVE_MNTENT_H
    33 #    undef PHYSFS_HAVE_MNTENT_H /* don't do both... */
    36 #    undef PHYSFS_HAVE_MNTENT_H /* don't do both... */
    34 #  endif
    37 #  endif
   254     free(envr);
   257     free(envr);
   255     return(retval);
   258     return(retval);
   256 } /* __PHYSFS_platformCalcBaseDir */
   259 } /* __PHYSFS_platformCalcBaseDir */
   257 
   260 
   258 
   261 
   259 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
       
   260 {
       
   261     return((PHYSFS_uint64) pthread_self());
       
   262 } /* __PHYSFS_platformGetThreadID */
       
   263 
       
   264 
       
   265 /* Much like my college days, try to sleep for 10 milliseconds at a time... */
   262 /* Much like my college days, try to sleep for 10 milliseconds at a time... */
   266 void __PHYSFS_platformTimeslice(void)
   263 void __PHYSFS_platformTimeslice(void)
   267 {
   264 {
   268     usleep( 10 * 1000 );           /* don't care if it fails. */
   265     usleep( 10 * 1000 );           /* don't care if it fails. */
   269 } /* __PHYSFS_platformTimeslice */
   266 } /* __PHYSFS_platformTimeslice */
   279     retval = (char *) malloc(strlen(resolved_path) + 1);
   276     retval = (char *) malloc(strlen(resolved_path) + 1);
   280     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   277     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   281     strcpy(retval, resolved_path);
   278     strcpy(retval, resolved_path);
   282     return(retval);
   279     return(retval);
   283 } /* __PHYSFS_platformRealPath */
   280 } /* __PHYSFS_platformRealPath */
       
   281 
       
   282 
       
   283 #if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
       
   284 
       
   285 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) { return(0x0001); }
       
   286 void *__PHYSFS_platformCreateMutex(void) { return((void *) 0x0001); }
       
   287 void __PHYSFS_platformDestroyMutex(void *mutex) {}
       
   288 int __PHYSFS_platformGrabMutex(void *mutex) { return(1); }
       
   289 void __PHYSFS_platformReleaseMutex(void *mutex) {}
       
   290 
       
   291 #else
       
   292 
       
   293 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
       
   294 {
       
   295     return((PHYSFS_uint64) pthread_self());
       
   296 } /* __PHYSFS_platformGetThreadID */
   284 
   297 
   285 
   298 
   286 void *__PHYSFS_platformCreateMutex(void)
   299 void *__PHYSFS_platformCreateMutex(void)
   287 {
   300 {
   288     int rc;
   301     int rc;
   315 void __PHYSFS_platformReleaseMutex(void *mutex)
   328 void __PHYSFS_platformReleaseMutex(void *mutex)
   316 {
   329 {
   317     pthread_mutex_unlock((pthread_mutex_t *) mutex);
   330     pthread_mutex_unlock((pthread_mutex_t *) mutex);
   318 } /* __PHYSFS_platformReleaseMutex */
   331 } /* __PHYSFS_platformReleaseMutex */
   319 
   332 
       
   333 #endif /* !PHYSFS_NO_PTHREADS_SUPPORT */
       
   334 
       
   335 
   320 #endif /* !defined __BEOS__ && !defined WIN32 */
   336 #endif /* !defined __BEOS__ && !defined WIN32 */
   321 
   337 
   322 /* end of unix.c ... */
   338 /* end of unix.c ... */
   323 
   339