platform/unix.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 06 Apr 2002 21:05:14 +0000
changeset 188 41bf2cb44d12
parent 171 0d92d6358410
child 191 0b95b9fd25e3
permissions -rw-r--r--
Darwin fixes.
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
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
     9
#if ((defined __APPLE__) && (defined __MACH__))
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    10
#  if (!defined __DARWIN__)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    11
#    define __DARWIN__
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    12
#  endif
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    13
#endif
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    14
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    15
#if (defined __STRICT_ANSI__)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    16
#define __PHYSFS_DOING_STRICT_ANSI__
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    17
#endif
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    18
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    19
/*
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    20
 * We cheat a little: I want the symlink version of stat() (lstat), and
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    21
 *  GCC/Linux will not declare it if compiled with the -ansi flag.
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    22
 *  If you are really lacking symlink support on your platform,
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    23
 *  you should #define __PHYSFS_NO_SYMLINKS__ before compiling this
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    24
 *  file. That will open a security hole, though, if you really DO have
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    25
 *  symlinks on your platform; it renders PHYSFS_permitSymbolicLinks(0)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    26
 *  useless, since every symlink will be reported as a regular file/dir.
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    27
 */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    28
#if (defined __PHYSFS_DOING_STRICT_ANSI__)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    29
#undef __STRICT_ANSI__
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    30
#endif
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#include <stdio.h>
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    32
#if (defined __PHYSFS_DOING_STRICT_ANSI__)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    33
#define __STRICT_ANSI__
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    34
#endif
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
    35
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#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
    37
#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
    38
#include <ctype.h>
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#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
    40
#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
    41
#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
    42
#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
    43
#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
    44
#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
    45
#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
    46
#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
    47
#include <errno.h>
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    48
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    49
#if (!defined __DARWIN__)
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
    50
#include <mntent.h>
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    51
#else
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    52
#include <sys/ucred.h>
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    53
#endif
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
    54
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    55
#include <sys/mount.h>
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    56
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
#define __PHYSICSFS_INTERNAL__
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
#include "physfs_internal.h"
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
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
const char *__PHYSFS_platformDirSeparator = "/";
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    64
130
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    65
int __PHYSFS_platformInit(void)
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    66
{
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    67
    return(1);  /* always succeed. */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    68
} /* __PHYSFS_platformInit */
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
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    71
int __PHYSFS_platformDeinit(void)
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    72
{
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    73
    return(1);  /* always succeed. */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    74
} /* __PHYSFS_platformDeinit */
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    75
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    76
2deec3eb7430 Added __PHYSFS_platformInit() and __PHYSFS_platformDeinit().
Ryan C. Gordon <icculus@icculus.org>
parents: 117
diff changeset
    77
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    78
#if (defined __DARWIN__)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    79
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    80
char **__PHYSFS_platformDetectAvailableCDs(void)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    81
{
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    82
    char **retval = (char **) malloc(sizeof (char *));
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    83
    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
    84
    struct statfs* mntbufp = NULL;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    85
    int mounts;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    86
    int ii;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    87
171
0d92d6358410 Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    88
    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
    89
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    90
    mounts = getmntinfo( &mntbufp, MNT_WAIT );
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    91
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    92
    for ( ii=0; ii < mounts; ++ii ) {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    93
        int add_it = 0;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    94
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    95
        if ( strcmp( mntbufp[ii].f_fstypename, "iso9660") == 0 )
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    96
            add_it = 1;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    97
        /* !!! other mount types? */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    98
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
    99
        if (add_it)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   100
        {
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   101
            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
   102
            if (tmp)
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
                retval = tmp;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   105
                retval[cd_count-1] = (char *)
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   106
                                malloc(strlen(mntbufp[ ii ].f_mntonname) + 1);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   107
                if (retval[cd_count-1])
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
                    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
   110
                    cd_count++;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   111
                } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   112
            } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   113
        } /* if */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   114
    }
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   115
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   116
    free( mntbufp );
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   118
    retval[cd_count - 1] = NULL;
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   119
    return(retval);
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   120
} /* __PHYSFS_platformDetectAvailableCDs */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   121
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   122
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   123
#else  /* non-Darwin implementation... */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   124
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   125
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
char **__PHYSFS_platformDetectAvailableCDs(void)
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
{
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   128
    char **retval = (char **) malloc(sizeof (char *));
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   129
    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
   130
    FILE *mounts = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   131
    struct mntent *ent = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   132
171
0d92d6358410 Added some malloc() failure checks in CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   133
    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
   134
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   135
    *retval = NULL;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   136
    mounts = setmntent("/etc/mtab", "r");
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   137
    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
   138
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   139
    while ( (ent = getmntent(mounts)) != NULL )
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   140
    {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   141
        int add_it = 0;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   142
        if (strcmp(ent->mnt_type, "iso9660") == 0)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   143
            add_it = 1;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   144
        /* !!! other mount types? */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   145
63
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   146
        if (add_it)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   147
        {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   148
            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
   149
            if (tmp)
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   150
            {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   151
                retval = tmp;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   152
                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
   153
                if (retval[cd_count-1])
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   154
                {
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   155
                    strcpy(retval[cd_count-1], ent->mnt_dir);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   156
                    cd_count++;
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   157
                } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   158
            } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   159
        } /* if */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   160
    } /* while */
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   161
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   162
    endmntent(mounts);
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   163
cb9a4714b844 Added CD-ROM detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 41
diff changeset
   164
    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
   165
    return(retval);
117
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   166
} /* __PHYSFS_platformDetectAvailableCDs */
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   167
55ae10d7f2a9 Darwin support by Patrick Stein.
Ryan C. Gordon <icculus@icculus.org>
parents: 115
diff changeset
   168
#endif
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   171
static char *copyEnvironmentVariable(const char *varname)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   172
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   173
    const char *envr = getenv(varname);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   174
    char *retval = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   175
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   176
    if (envr != NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   177
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   178
        retval = malloc(strlen(envr) + 1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   179
        if (retval != NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   180
            strcpy(retval, envr);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   181
    } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   182
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   183
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   184
} /* copyEnvironmentVariable */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   185
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   186
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   187
/* !!! this is ugly. */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   188
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
   189
{
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   190
    /* 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
   191
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   192
    char *retval = NULL;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   193
    char *envr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   194
    char *start;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   195
    char *ptr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   196
    char *exe;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   197
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   198
    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
   199
        return(NULL);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   200
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   201
    envr = copyEnvironmentVariable("PATH");
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   202
    BAIL_IF_MACRO(!envr, NULL, NULL);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   203
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   204
    start = envr;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   205
    do
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   206
    {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   207
        ptr = strchr(start, ':');
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   208
        if (ptr)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   209
            *ptr = '\0';
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   210
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   211
        exe = (char *) malloc(strlen(start) + strlen(argv0) + 2);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   212
        if (!exe)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   213
        {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   214
            free(envr);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   215
            BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   216
        } /* if */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   217
        strcpy(exe, start);
79
5dbb03944ef0 Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   218
        if (exe[strlen(exe) - 1] != '/')
5dbb03944ef0 Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   219
            strcat(exe, "/");
5dbb03944ef0 Fixed base directory determination.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   220
        strcat(exe, argv0);
23
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   221
        if (access(exe, X_OK) != 0)
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   222
            free(exe);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   223
        else
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   224
        {
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   225
            retval = exe;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   226
            strcpy(retval, start);  /* i'm lazy. piss off. */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   227
            break;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   228
        } /* else */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   229
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   230
        start = ptr + 1;
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   231
    } while (ptr != NULL);
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
    free(envr);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   234
    return(retval);
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   235
} /* __PHYSFS_platformCalcBaseDir */
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   236
bd6ba9c8717c Initial debugging: dropped PhysicsFS routines into the Build engine,
Ryan C. Gordon <icculus@icculus.org>
parents: 20
diff changeset
   237
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   238
static char *getUserNameByUID(void)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   239
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   240
    uid_t uid = getuid();
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   241
    struct passwd *pw;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   242
    char *retval = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   243
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   244
    pw = getpwuid(uid);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   245
    if ((pw != NULL) && (pw->pw_name != NULL))
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   246
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   247
        retval = malloc(strlen(pw->pw_name) + 1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   248
        if (retval != NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   249
            strcpy(retval, pw->pw_name);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   250
    } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   251
    
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   252
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   253
} /* getUserNameByUID */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   254
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
static char *getUserDirByUID(void)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   257
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   258
    uid_t uid = getuid();
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   259
    struct passwd *pw;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   260
    char *retval = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   261
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   262
    pw = getpwuid(uid);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   263
    if ((pw != NULL) && (pw->pw_dir != NULL))
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   264
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   265
        retval = malloc(strlen(pw->pw_dir) + 1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   266
        if (retval != NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   267
            strcpy(retval, pw->pw_dir);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   268
    } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   269
    
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   270
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   271
} /* getUserDirByUID */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   272
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   273
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
char *__PHYSFS_platformGetUserName(void)
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
{
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   276
    char *retval = getUserNameByUID();
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   277
    if (retval == NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   278
        retval = copyEnvironmentVariable("USER");
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   279
    return(retval);
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
} /* __PHYSFS_platformGetUserName */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
char *__PHYSFS_platformGetUserDir(void)
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
{
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   285
    char *retval = copyEnvironmentVariable("HOME");
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   286
    if (retval == NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   287
        retval = getUserDirByUID();
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   288
    return(retval);
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
} /* __PHYSFS_platformGetUserDir */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   292
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
{
188
41bf2cb44d12 Darwin fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 171
diff changeset
   294
    return((PHYSFS_uint64) ((PHYSFS_uint32) pthread_self()));
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
} /* __PHYSFS_platformGetThreadID */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   298
/* -ansi and -pedantic flags prevent use of strcasecmp() on Linux. */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   299
int __PHYSFS_platformStricmp(const char *x, const char *y)
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
{
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   301
    int ux, uy;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   302
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   303
    do
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   304
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   305
        ux = toupper((int) *x);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   306
        uy = toupper((int) *y);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   307
        if (ux > uy)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   308
            return(1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   309
        else if (ux < uy)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   310
            return(-1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   311
        x++;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   312
        y++;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   313
    } while ((ux) && (uy));
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   314
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   315
    return(0);
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
} /* __PHYSFS_platformStricmp */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   319
int __PHYSFS_platformExists(const char *fname)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   320
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   321
    struct stat statbuf;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   322
    return(stat(fname, &statbuf) == 0);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   323
} /* __PHYSFS_platformExists */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   324
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   325
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   326
int __PHYSFS_platformIsSymLink(const char *fname)
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
{
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   328
#if (defined __PHYSFS_NO_SYMLINKS__)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   329
    return(0);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   330
#else
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   331
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   332
    struct stat statbuf;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   333
    int retval = 0;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   334
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   335
    if (lstat(fname, &statbuf) == 0)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   336
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   337
        if (S_ISLNK(statbuf.st_mode))
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   338
            retval = 1;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   339
    } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   340
    
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   341
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   342
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   343
#endif
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
} /* __PHYSFS_platformIsSymlink */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
int __PHYSFS_platformIsDirectory(const char *fname)
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
{
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   349
    struct stat statbuf;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   350
    int retval = 0;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   351
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   352
    if (stat(fname, &statbuf) == 0)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   353
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   354
        if (S_ISDIR(statbuf.st_mode))
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   355
            retval = 1;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   356
    } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   357
    
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   358
    return(retval);
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
} /* __PHYSFS_platformIsDirectory */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   362
char *__PHYSFS_platformCvtToDependent(const char *prepend,
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   363
                                      const char *dirName,
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   364
                                      const char *append)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   365
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   366
    int len = ((prepend) ? strlen(prepend) : 0) +
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   367
              ((append) ? strlen(append) : 0) +
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   368
              strlen(dirName) + 1;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   369
    char *retval = malloc(len);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   370
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   371
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   372
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   373
    /* platform-independent notation is Unix-style already.  :)  */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   374
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   375
    if (prepend)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   376
        strcpy(retval, prepend);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   377
    else
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   378
        retval[0] = '\0';
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   379
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   380
    strcat(retval, dirName);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   381
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   382
    if (append)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   383
        strcat(retval, append);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   384
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   385
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   386
} /* __PHYSFS_platformCvtToDependent */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   387
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   388
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   389
/* 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
   390
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
   391
{
115
c0671785777b Changed timeslice implementation to use something more portable (thanks to
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   392
    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
   393
} /* __PHYSFS_platformTimeslice */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   394
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   395
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   396
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   397
                                                  int omitSymLinks)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   398
{
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   399
    LinkedStringList *retval = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   400
    LinkedStringList *l = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   401
    LinkedStringList *prev = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   402
    DIR *dir;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   403
    struct dirent *ent;
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   404
    int bufsize = 0;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   405
    char *buf = NULL;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   406
    int dlen = 0;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   407
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   408
    if (omitSymLinks)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   409
    {
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   410
        dlen = strlen(dirname);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   411
        bufsize = dlen + 256;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   412
        buf = malloc(bufsize);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   413
        BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, NULL);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   414
        strcpy(buf, dirname);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   415
        if (buf[dlen - 1] != '/')
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   416
        {
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   417
            buf[dlen++] = '/';
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   418
            buf[dlen] = '\0';
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   419
        } /* if */
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   420
    } /* if */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   421
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   422
    errno = 0;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   423
    dir = opendir(dirname);
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   424
    if (dir == NULL)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   425
    {
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   426
        if (buf != NULL)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   427
            free(buf);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   428
        BAIL_IF_MACRO(1, strerror(errno), NULL);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   429
    } /* if */
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   430
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   431
    while (1)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   432
    {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   433
        ent = readdir(dir);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   434
        if (ent == NULL)   /* we're done. */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   435
            break;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   436
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   437
        if (strcmp(ent->d_name, ".") == 0)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   438
            continue;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   439
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   440
        if (strcmp(ent->d_name, "..") == 0)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   441
            continue;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   442
41
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   443
        if (omitSymLinks)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   444
        {
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   445
            char *p;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   446
            int len = strlen(ent->d_name) + dlen + 1;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   447
            if (len > bufsize)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   448
            {
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   449
                p = realloc(buf, len);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   450
                if (p == NULL)
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   451
                    continue;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   452
                buf = p;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   453
                bufsize = len;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   454
            } /* if */
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   455
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   456
            strcpy(buf + dlen, ent->d_name);
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   457
            if (__PHYSFS_platformIsSymLink(buf))
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   458
                continue;
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   459
        } /* if */
ff60d39d0862 Architecture adjustment for enumerating files with regards to whether
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   460
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   461
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   462
        if (l == NULL)
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   463
            break;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   464
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   465
        l->str = (char *) malloc(strlen(ent->d_name) + 1);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   466
        if (l->str == NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   467
        {
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   468
            free(l);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   469
            break;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   470
        } /* if */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   471
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   472
        strcpy(l->str, ent->d_name);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   473
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   474
        if (retval == NULL)
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   475
            retval = l;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   476
        else
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   477
            prev->next = l;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   478
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   479
        prev = l;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   480
        l->next = NULL;
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   481
    } /* while */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   482
67
5000499d4ee2 Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents: 63
diff changeset
   483
    if (buf != NULL)
5000499d4ee2 Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents: 63
diff changeset
   484
        free(buf);
5000499d4ee2 Fixed a potential free()ing of a NULL pointer in
Ryan C. Gordon <icculus@icculus.org>
parents: 63
diff changeset
   485
20
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   486
    closedir(dir);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   487
    return(retval);
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   488
} /* __PHYSFS_platformEnumerateFiles */
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   489
efdde0d21521 Implementation compiles and links with no actual archive support. No test
Ryan C. Gordon <icculus@icculus.org>
parents: 17
diff changeset
   490
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   491
char *__PHYSFS_platformCurrentDir(void)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   492
{
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   493
    int allocSize = 0;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   494
    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
   495
    char *ptr;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   496
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   497
    do
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
        allocSize += 100;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   500
        ptr = (char *) realloc(retval, allocSize);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   501
        if (ptr == NULL)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   502
        {
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   503
            if (retval != NULL)
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   504
                free(retval);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   505
            BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   506
        } /* if */
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   507
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   508
        retval = ptr;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   509
        ptr = getcwd(retval, allocSize);
100
d2f04ab4b412 Patches from David Hedbor to handle missing current working directories.
Ryan C. Gordon <icculus@icculus.org>
parents: 79
diff changeset
   510
    } while (ptr == NULL && errno == ERANGE);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   511
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   512
    if (ptr == NULL && errno)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   513
    {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   514
            /*
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   515
             * getcwd() failed for some reason, for example current
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   516
             * directory not existing.
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   517
             */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   518
        if (retval != NULL)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   519
            free(retval);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   520
        BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   521
    } /* if */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   522
39
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   523
    return(retval);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   524
} /* __PHYSFS_platformCurrentDir */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   525
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   526
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   527
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
   528
{
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   529
    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
   530
    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
   531
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   532
    errno = 0;
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   533
    BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   534
    retval = malloc(strlen(resolved_path) + 1);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   535
    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
   536
    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
   537
    return(retval);
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   538
} /* __PHYSFS_platformRealPath */
bc29e1ee7ef6 Lots of bugfixes, enhancements, and corrections due to the work on
Ryan C. Gordon <icculus@icculus.org>
parents: 28
diff changeset
   539
69
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   540
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   541
int __PHYSFS_platformMkDir(const char *path)
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   542
{
70
203efbe2532e Whoops. Forgot to declare a variable.
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
   543
    int rc;
69
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   544
    errno = 0;
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   545
    rc = mkdir(path, S_IRWXU);
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   546
    BAIL_IF_MACRO(rc == -1, strerror(errno), 0);
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   547
    return(1);
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   548
} /* __PHYSFS_platformMkDir */
546a95cc5591 Updates, corrections and enhancements to get this ported to win32.
Ryan C. Gordon <icculus@icculus.org>
parents: 67
diff changeset
   549
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   550
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   551
static void *doOpen(const char *filename, const char *mode)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   552
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   553
    FILE *retval;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   554
    errno = 0;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   555
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   556
    retval = fopen(filename, mode);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   557
    if (retval == NULL)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   558
        __PHYSFS_setError(strerror(errno));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   559
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   560
    return((void *) retval);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   561
} /* doOpen */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   562
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   563
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   564
void *__PHYSFS_platformOpenRead(const char *filename)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   565
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   566
    return(doOpen(filename, "rb"));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   567
} /* __PHYSFS_platformOpenRead */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   568
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   569
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   570
void *__PHYSFS_platformOpenWrite(const char *filename)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   571
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   572
    return(doOpen(filename, "wb"));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   573
} /* __PHYSFS_platformOpenWrite */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   574
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   575
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   576
void *__PHYSFS_platformOpenAppend(const char *filename)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   577
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   578
    return(doOpen(filename, "wb+"));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   579
} /* __PHYSFS_platformOpenAppend */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   580
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   581
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   582
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   583
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   584
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   585
    FILE *io = (FILE *) opaque;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   586
    int rc = fread(buffer, size, count, io);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   587
    if (rc < count)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   588
    {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   589
        int err = errno;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   590
        BAIL_IF_MACRO(ferror(io), strerror(err), rc);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   591
        BAIL_MACRO(ERR_PAST_EOF, rc);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   592
    } /* if */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   593
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   594
    return(rc);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   595
} /* __PHYSFS_platformRead */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   596
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   597
133
293f14af15c8 Quick fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   598
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   599
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   600
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   601
    FILE *io = (FILE *) opaque;
133
293f14af15c8 Quick fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 132
diff changeset
   602
    int rc = fwrite((void *) buffer, size, count, io);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   603
    if (rc < count)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   604
        __PHYSFS_setError(strerror(errno));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   605
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   606
    return(rc);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   607
} /* __PHYSFS_platformWrite */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   608
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   609
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   610
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   611
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   612
    FILE *io = (FILE *) opaque;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   613
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   614
    /* !!! FIXME: Use llseek where available. */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   615
    errno = 0;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   616
    BAIL_IF_MACRO(fseek(io, pos, SEEK_SET) != 0, strerror(errno), 0);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   617
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   618
    return(1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   619
} /* __PHYSFS_platformSeek */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   620
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   621
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   622
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   623
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   624
    FILE *io = (FILE *) opaque;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   625
    PHYSFS_sint64 retval = ftell(io);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   626
    BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   627
    return(retval);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   628
} /* __PHYSFS_platformTell */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   629
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   630
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   631
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   632
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   633
    FILE *io = (FILE *) opaque;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   634
    struct stat statbuf;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   635
    errno = 0;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   636
    BAIL_IF_MACRO(fstat(fileno(io), &statbuf) == -1, strerror(errno), -1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   637
    return((PHYSFS_sint64) statbuf.st_size);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   638
} /* __PHYSFS_platformFileLength */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   639
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   640
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   641
int __PHYSFS_platformEOF(void *opaque)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   642
{
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   643
    return(feof((FILE *) opaque));
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   644
} /* __PHYSFS_platformEOF */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   645
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   646
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   647
int __PHYSFS_platformFlush(void *opaque)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   648
{
137
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   649
    errno = 0;
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   650
    BAIL_IF_MACRO(fflush((FILE *) opaque) == EOF, strerror(errno), 0);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   651
    return(1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   652
} /* __PHYSFS_platformFlush */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   653
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   654
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   655
int __PHYSFS_platformClose(void *opaque)
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   656
{
137
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   657
    errno = 0;
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   658
    BAIL_IF_MACRO(fclose((FILE *) opaque) == EOF, strerror(errno), 0);
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   659
    return(1);
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   660
} /* __PHYSFS_platformClose */
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   661
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 130
diff changeset
   662
137
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   663
int __PHYSFS_platformDelete(const char *path)
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   664
{
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   665
    errno = 0;
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   666
    BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0);
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   667
    return(1);
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   668
} /* __PHYSFS_platformDelete */
66bddb94b6e0 Abstracted file deletion, so we don't rely on C library for it anymore.
Ryan C. Gordon <icculus@icculus.org>
parents: 133
diff changeset
   669
145
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   670
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   671
void *__PHYSFS_platformCreateMutex(void)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   672
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   673
    int rc;
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   674
    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
   675
    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
   676
    rc = pthread_mutex_init(m, NULL);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   677
    if (rc != 0)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   678
    {
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   679
        free(m);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   680
        BAIL_MACRO(strerror(rc), NULL);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   681
    } /* if */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   682
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   683
    return((void *) m);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   684
} /* __PHYSFS_platformCreateMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   685
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   686
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   687
void __PHYSFS_platformDestroyMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   688
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   689
    pthread_mutex_destroy((pthread_mutex_t *) mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   690
    free(mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   691
} /* __PHYSFS_platformDestroyMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   692
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   693
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   694
int __PHYSFS_platformGrabMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   695
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   696
    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
   697
} /* __PHYSFS_platformGrabMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   698
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   699
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   700
void __PHYSFS_platformReleaseMutex(void *mutex)
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   701
{
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   702
    pthread_mutex_unlock((pthread_mutex_t *) mutex);
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   703
} /* __PHYSFS_platformReleaseMutex */
d6385584f6c4 First shot at thread-safety.
Ryan C. Gordon <icculus@icculus.org>
parents: 137
diff changeset
   704
17
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
/* end of unix.c ... */
7337737f5120 Moved from root source dir.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706