platform/unix.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 08 Jun 2002 20:59:29 +0000
changeset 273 9451eff9f495
parent 233 1b74a7df1ca6
child 310 f8bca4a93fd5
permissions -rw-r--r--
Fixed incorrect free() in Darwin CD detection code.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
    13
#if (!defined __BEOS__) /* BeOS uses beos.cpp and 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
    14
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    15
#if ((defined __APPLE__) && (defined __MACH__))
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    16
#  if (!defined __DARWIN__)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    17
#    define __DARWIN__
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    18
#  endif
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    19
#endif
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    20
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <stdio.h>
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#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
    23
#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
    24
#include <ctype.h>
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#include <pthread.h>
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    26
#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
    27
#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
    28
#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
    29
#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
    30
#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
    31
#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
    32
#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
    33
#include <errno.h>
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    34
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    35
#if (!defined __DARWIN__)
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
    36
#include <mntent.h>
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    37
#else
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    38
#include <sys/ucred.h>
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    39
#endif
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    40
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    41
#include <sys/mount.h>
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    42
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#define __PHYSICSFS_INTERNAL__
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#include "physfs_internal.h"
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
const char *__PHYSFS_platformDirSeparator = "/";
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    50
130
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    51
int __PHYSFS_platformInit(void)
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    52
{
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    53
    return(1);  /* always succeed. */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    54
} /* __PHYSFS_platformInit */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    55
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    56
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    57
int __PHYSFS_platformDeinit(void)
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    58
{
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    59
    return(1);  /* always succeed. */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    60
} /* __PHYSFS_platformDeinit */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    61
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    62
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    63
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    64
#if (defined __DARWIN__)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    65
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    66
char **__PHYSFS_platformDetectAvailableCDs(void)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    67
{
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    68
    char **retval = (char **) malloc(sizeof (char *));
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    69
    int cd_count = 1;  /* We count the NULL entry. */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    70
    struct statfs* mntbufp = NULL;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    71
    int mounts;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    72
    int ii;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    73
171
0d92d6358410 Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    74
    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
    75
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    76
    mounts = getmntinfo( &mntbufp, MNT_WAIT );
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    77
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    78
    for ( ii=0; ii < mounts; ++ii ) {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    79
        int add_it = 0;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    80
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    81
        if ( strcmp( mntbufp[ii].f_fstypename, "iso9660") == 0 )
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    82
            add_it = 1;
191
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
    83
        else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 )
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
    84
            add_it = 1;
225
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
    85
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
    86
        /* add other mount types here */
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    87
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    88
        if (add_it)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    89
        {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    90
            char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    91
            if (tmp)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    92
            {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    93
                retval = tmp;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    94
                retval[cd_count-1] = (char *)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    95
                                malloc(strlen(mntbufp[ ii ].f_mntonname) + 1);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    96
                if (retval[cd_count-1])
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    97
                {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    98
                    strcpy(retval[cd_count-1], mntbufp[ ii ].f_mntonname);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    99
                    cd_count++;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   100
                } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   101
            } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   102
        } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   103
    }
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   104
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   105
    retval[cd_count - 1] = NULL;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   106
    return(retval);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   107
} /* __PHYSFS_platformDetectAvailableCDs */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   108
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   109
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   110
#else  /* non-Darwin implementation... */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   111
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   112
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
char **__PHYSFS_platformDetectAvailableCDs(void)
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
{
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   115
    char **retval = (char **) malloc(sizeof (char *));
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   116
    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
   117
    FILE *mounts = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   118
    struct mntent *ent = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   119
171
0d92d6358410 Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   120
    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
   121
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   122
    *retval = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   123
    mounts = setmntent("/etc/mtab", "r");
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   124
    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
   125
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   126
    while ( (ent = getmntent(mounts)) != NULL )
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   127
    {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   128
        int add_it = 0;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   129
        if (strcmp(ent->mnt_type, "iso9660") == 0)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   130
            add_it = 1;
225
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   131
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   132
        /* 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
   133
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   134
        if (add_it)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   135
        {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   136
            char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   137
            if (tmp)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   138
            {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   139
                retval = tmp;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   140
                retval[cd_count-1] = (char *) malloc(strlen(ent->mnt_dir) + 1);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   141
                if (retval[cd_count-1])
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   142
                {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   143
                    strcpy(retval[cd_count-1], ent->mnt_dir);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   144
                    cd_count++;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   145
                } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   146
            } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   147
        } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   148
    } /* while */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   149
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   150
    endmntent(mounts);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   151
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   152
    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
   153
    return(retval);
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   154
} /* __PHYSFS_platformDetectAvailableCDs */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   155
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   156
#endif
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
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
   159
/* 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
   160
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
   161
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   162
225
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   163
/*
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   164
 * See where program (bin) resides in the $PATH specified by (envr).
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   165
 *  returns a copy of the first element in envr that contains it, or NULL
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   166
 *  if it doesn't exist or there were other problems. PHYSFS_SetError() is
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   167
 *  called if we have a problem.
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   168
 *
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   169
 * (envr) will be scribbled over, and you are expected to free() the
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   170
 *  return value when you're done with it.
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   171
 */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   172
static char *findBinaryInPath(const char *bin, char *envr)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   173
{
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   174
    size_t alloc_size = 0;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   175
    char *exe = NULL;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   176
    char *start = envr;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   177
    char *ptr;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   178
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   179
    BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   180
    BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   181
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   182
    do
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   183
    {
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   184
        size_t size;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   185
        ptr = strchr(start, ':');  /* find next $PATH separator. */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   186
        if (ptr)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   187
            *ptr = '\0';
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   188
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   189
        size = strlen(start) + strlen(bin) + 2;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   190
        if (size > alloc_size)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   191
        {
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   192
            char *x = (char *) realloc(exe, size);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   193
            if (x == NULL)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   194
            {
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   195
                if (exe != NULL)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   196
                    free(exe);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   197
                BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   198
            } /* if */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   199
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   200
            alloc_size = size;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   201
            exe = x;
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   202
        } /* if */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   203
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   204
        /* build full binary path... */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   205
        strcpy(exe, start);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   206
        if (exe[strlen(exe) - 1] != '/')
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   207
            strcat(exe, "/");
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   208
        strcat(exe, bin);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   209
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   210
        if (access(exe, X_OK) == 0)  /* Exists as executable? We're done. */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   211
        {
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   212
            strcpy(exe, start);  /* i'm lazy. piss off. */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   213
            return(exe);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   214
        } /* if */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   215
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   216
        start = ptr + 1;  /* start points to beginning of next element. */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   217
    } while (ptr != NULL);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   218
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   219
    if (exe != NULL)
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   220
        free(exe);
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   221
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   222
    return(NULL);  /* doesn't exist in path. */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   223
} /* findBinaryInPath */
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   224
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   225
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   226
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
   227
{
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   228
    /* 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
   229
225
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   230
    char *retval;
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   231
    char *envr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   232
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   233
    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
   234
        return(NULL);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   235
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
   236
    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
   237
    BAIL_IF_MACRO(!envr, NULL, NULL);
225
393c0923c1b3 FIXME removal.
Ryan C. Gordon <icculus@icculus.org>
parents: 220
diff changeset
   238
    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
   239
    free(envr);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   240
    return(retval);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   241
} /* __PHYSFS_platformCalcBaseDir */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   242
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   243
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   244
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
{
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
   246
    return((PHYSFS_uint64) ((PHYSFS_uint32) pthread_self()));
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
} /* __PHYSFS_platformGetThreadID */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   250
/* 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
   251
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
   252
{
115
c0671785777b Changed timeslice implementation to use something more portable (thanks to
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   253
    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
   254
} /* __PHYSFS_platformTimeslice */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   255
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   256
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   257
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
   258
{
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   259
    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
   260
    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
   261
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   262
    errno = 0;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   263
    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
   264
    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
   265
    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
   266
    strcpy(retval, resolved_path);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   267
    return(retval);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   268
} /* __PHYSFS_platformRealPath */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   269
69
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   270
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   271
void *__PHYSFS_platformCreateMutex(void)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   272
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   273
    int rc;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   274
    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
   275
    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
   276
    rc = pthread_mutex_init(m, NULL);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   277
    if (rc != 0)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   278
    {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   279
        free(m);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   280
        BAIL_MACRO(strerror(rc), NULL);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   281
    } /* if */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   282
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   283
    return((void *) m);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   284
} /* __PHYSFS_platformCreateMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   285
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   286
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   287
void __PHYSFS_platformDestroyMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   288
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   289
    pthread_mutex_destroy((pthread_mutex_t *) mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   290
    free(mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   291
} /* __PHYSFS_platformDestroyMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   292
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   293
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   294
int __PHYSFS_platformGrabMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   295
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   296
    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
   297
} /* __PHYSFS_platformGrabMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   298
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   299
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   300
void __PHYSFS_platformReleaseMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   301
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   302
    pthread_mutex_unlock((pthread_mutex_t *) mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   303
} /* __PHYSFS_platformReleaseMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   304
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
   305
#endif /* !defined __BEOS__ */
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
   306
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
/* end of unix.c ... */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308