src/physfs_platform_posix.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 12 Aug 2017 02:19:22 -0400
changeset 1559 aaee2b83291f
parent 1543 210b82b60730
child 1581 ad04b99afb88
permissions -rw-r--r--
Reworked enumeration to be more powerful. Now callbacks can stop further enumeration and report errors, if they had a catastrophic issue or just found what they needed and don't need to process any more items. Also, the actual enumerators can report errors instead of silently dropping items. This led to several other fixes as all these implementations got audited and reworked. The original, non-callback enumerator now returns NULL if it can't produce a complete list instead of dropping items and returning a partial list.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Posix-esque support routines for PhysicsFS.
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
     9
/* !!! FIXME: check for EINTR? */
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    10
818
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    11
#define __PHYSICSFS_INTERNAL__
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    12
#include "physfs_platforms.h"
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    13
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    14
#ifdef PHYSFS_PLATFORM_POSIX
310
f8bca4a93fd5 Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 292
diff changeset
    15
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
    16
#include <unistd.h>
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <ctype.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#include <sys/types.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#include <sys/stat.h>
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
    20
#include <pwd.h>
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <dirent.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#include <errno.h>
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
    23
#include <fcntl.h>
1173
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
    24
#include <pthread.h>
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
    25
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include "physfs_internal.h"
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    28
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    29
static PHYSFS_ErrorCode errcodeFromErrnoError(const int err)
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    30
{
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    31
    switch (err)
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    32
    {
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    33
        case 0: return PHYSFS_ERR_OK;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    34
        case EACCES: return PHYSFS_ERR_PERMISSION;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    35
        case EPERM: return PHYSFS_ERR_PERMISSION;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    36
        case EDQUOT: return PHYSFS_ERR_NO_SPACE;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    37
        case EIO: return PHYSFS_ERR_IO;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    38
        case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    39
        case EMLINK: return PHYSFS_ERR_NO_SPACE;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    40
        case ENAMETOOLONG: return PHYSFS_ERR_BAD_FILENAME;
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1290
diff changeset
    41
        case ENOENT: return PHYSFS_ERR_NOT_FOUND;
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    42
        case ENOSPC: return PHYSFS_ERR_NO_SPACE;
1322
5476917b8ddf Allow application-supplied archivers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1290
diff changeset
    43
        case ENOTDIR: return PHYSFS_ERR_NOT_FOUND;
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    44
        case EISDIR: return PHYSFS_ERR_NOT_A_FILE;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    45
        case EROFS: return PHYSFS_ERR_READ_ONLY;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    46
        case ETXTBSY: return PHYSFS_ERR_BUSY;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    47
        case EBUSY: return PHYSFS_ERR_BUSY;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    48
        case ENOMEM: return PHYSFS_ERR_OUT_OF_MEMORY;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    49
        case ENOTEMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    50
        default: return PHYSFS_ERR_OS_ERROR;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    51
    } /* switch */
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    52
} /* errcodeFromErrnoError */
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    53
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    54
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    55
static inline PHYSFS_ErrorCode errcodeFromErrno(void)
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    56
{
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    57
    return errcodeFromErrnoError(errno);
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    58
} /* errcodeFromErrno */
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    59
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
    60
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
static char *getUserDirByUID(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    uid_t uid = getuid();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    struct passwd *pw;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    char *retval = NULL;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    pw = getpwuid(uid);
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    68
    if ((pw != NULL) && (pw->pw_dir != NULL) && (*pw->pw_dir != '\0'))
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    {
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    70
        const size_t dlen = strlen(pw->pw_dir);
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    71
        const size_t add_dirsep = (pw->pw_dir[dlen-1] != '/') ? 1 : 0;
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    72
        retval = (char *) allocator.Malloc(dlen + 1 + add_dirsep);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        if (retval != NULL)
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    74
        {
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            strcpy(retval, pw->pw_dir);
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    76
            if (add_dirsep)
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    77
            {
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    78
                retval[dlen] = '/';
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    79
                retval[dlen+1] = '\0';
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    80
            } /* if */
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    81
        } /* if */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
    84
    return retval;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
} /* getUserDirByUID */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
1248
632895970ed6 Cleaned up some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
    88
char *__PHYSFS_platformCalcUserDir(void)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
{
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    90
    char *retval = NULL;
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    91
    char *envr = getenv("HOME");
1073
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    92
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    93
    /* if the environment variable was set, make sure it's really a dir. */
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    94
    if (envr != NULL)
1073
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    95
    {
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    96
        struct stat statbuf;
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    97
        if ((stat(envr, &statbuf) != -1) && (S_ISDIR(statbuf.st_mode)))
1073
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
    98
        {
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
    99
            const size_t envrlen = strlen(envr);
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   100
            const size_t add_dirsep = (envr[envrlen-1] != '/') ? 1 : 0;
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   101
            retval = allocator.Malloc(envrlen + 1 + add_dirsep);
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   102
            if (retval)
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   103
            {
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   104
                strcpy(retval, envr);
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   105
                if (add_dirsep)
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   106
                {
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   107
                    retval[envrlen] = '/';
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   108
                    retval[envrlen+1] = '\0';
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   109
                } /* if */
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1249
diff changeset
   110
            } /* if */
1073
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   111
        } /* if */
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   112
    } /* if */
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   113
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    if (retval == NULL)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        retval = getUserDirByUID();
1073
b45193ab2033 See if $HOME is bogus, and if so, use getpwuid() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   116
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   117
    return retval;
1248
632895970ed6 Cleaned up some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   118
} /* __PHYSFS_platformCalcUserDir */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   121
int __PHYSFS_platformEnumerate(const char *dirname,
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   122
                               PHYSFS_EnumerateCallback callback,
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   123
                               const char *origdir, void *callbackdata)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    DIR *dir;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    struct dirent *ent;
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   127
    int retval = 1;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    dir = opendir(dirname);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   130
    BAIL_IF(dir == NULL, errcodeFromErrno(), -1);
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   131
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   132
    while ((retval == 1) && ((ent = readdir(dir)) != NULL))
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    {
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   134
        const char *name = ent->d_name;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   135
        if (name[0] == '.')  /* ignore "." and ".." */
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   136
        {
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   137
            if ((name[1] == '\0') || ((name[1] == '.') && (name[2] == '\0')))
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   138
                continue;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   139
        } /* if */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   141
        retval = callback(callbackdata, origdir, name);
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   142
        if (retval == -1)
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   143
            PHYSFS_setErrorCode(PHYSFS_ERR_APP_CALLBACK);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    closedir(dir);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   147
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   148
    return retval;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1543
diff changeset
   149
} /* __PHYSFS_platformEnumerate */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
int __PHYSFS_platformMkDir(const char *path)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
{
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   154
    const int rc = mkdir(path, S_IRWXU);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   155
    BAIL_IF(rc == -1, errcodeFromErrno(), 0);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   156
    return 1;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
} /* __PHYSFS_platformMkDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   160
static void *doOpen(const char *filename, int mode)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
{
939
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   162
    const int appending = (mode & O_APPEND);
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   163
    int fd;
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   164
    int *retval;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    errno = 0;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
939
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   167
    /* O_APPEND doesn't actually behave as we'd like. */
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   168
    mode &= ~O_APPEND;
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   169
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   170
    fd = open(filename, mode, S_IRUSR | S_IWUSR);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   171
    BAIL_IF(fd < 0, errcodeFromErrno(), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
939
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   173
    if (appending)
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   174
    {
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   175
        if (lseek(fd, 0, SEEK_END) < 0)
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   176
        {
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   177
            const int err = errno;
939
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   178
            close(fd);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   179
            BAIL(errcodeFromErrnoError(err), NULL);
939
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   180
        } /* if */
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   181
    } /* if */
684c583cb586 Fixed PHYSFS_openAppend() on Unix.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   182
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   183
    retval = (int *) allocator.Malloc(sizeof (int));
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   184
    if (!retval)
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   185
    {
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   186
        close(fd);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   187
        BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
251
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   188
    } /* if */
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   189
0f4615263e32 Actual POSIX calls to replace ANSI stdio routines.
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   190
    *retval = fd;
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   191
    return ((void *) retval);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
} /* doOpen */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
void *__PHYSFS_platformOpenRead(const char *filename)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   197
    return doOpen(filename, O_RDONLY);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
} /* __PHYSFS_platformOpenRead */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
void *__PHYSFS_platformOpenWrite(const char *filename)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   203
    return doOpen(filename, O_WRONLY | O_CREAT | O_TRUNC);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
} /* __PHYSFS_platformOpenWrite */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
void *__PHYSFS_platformOpenAppend(const char *filename)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   209
    return doOpen(filename, O_WRONLY | O_CREAT | O_APPEND);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
} /* __PHYSFS_platformOpenAppend */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   214
                                    PHYSFS_uint64 len)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   216
    const int fd = *((int *) opaque);
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   217
    ssize_t rc = 0;
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   218
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   219
    if (!__PHYSFS_ui64FitsAddressSpace(len))
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   220
        BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   222
    rc = read(fd, buffer, (size_t) len);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   223
    BAIL_IF(rc == -1, errcodeFromErrno(), -1);
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   224
    assert(rc >= 0);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   225
    assert(rc <= len);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   226
    return (PHYSFS_sint64) rc;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
} /* __PHYSFS_platformRead */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   231
                                     PHYSFS_uint64 len)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   233
    const int fd = *((int *) opaque);
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   234
    ssize_t rc = 0;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   236
    if (!__PHYSFS_ui64FitsAddressSpace(len))
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   237
        BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1);
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   238
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   239
    rc = write(fd, (void *) buffer, (size_t) len);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   240
    BAIL_IF(rc == -1, errcodeFromErrno(), rc);
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   241
    assert(rc >= 0);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   242
    assert(rc <= len);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1073
diff changeset
   243
    return (PHYSFS_sint64) rc;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
} /* __PHYSFS_platformWrite */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   249
    const int fd = *((int *) opaque);
1240
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1238
diff changeset
   250
    const int rc = lseek(fd, (off_t) pos, SEEK_SET);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   251
    BAIL_IF(rc == -1, errcodeFromErrno(), 0);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   252
    return 1;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
} /* __PHYSFS_platformSeek */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   258
    const int fd = *((int *) opaque);
259
bd65a0d74e9a 64-bit _llseek() support for the future.
Ryan C. Gordon <icculus@icculus.org>
parents: 255
diff changeset
   259
    PHYSFS_sint64 retval;
1228
7c0e9de2ba33 Removed llseek().
Ryan C. Gordon <icculus@icculus.org>
parents: 1226
diff changeset
   260
    retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   261
    BAIL_IF(retval == -1, errcodeFromErrno(), -1);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   262
    return retval;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
} /* __PHYSFS_platformTell */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   268
    const int fd = *((int *) opaque);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    struct stat statbuf;
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   270
    BAIL_IF(fstat(fd, &statbuf) == -1, errcodeFromErrno(), -1);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   271
    return ((PHYSFS_sint64) statbuf.st_size);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
} /* __PHYSFS_platformFileLength */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
int __PHYSFS_platformFlush(void *opaque)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
{
1117
968e1567f4f4 Constification.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   277
    const int fd = *((int *) opaque);
1335
1b9a72908ece Don't fsync() read-only filehandles (thanks, Andreas!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1327
diff changeset
   278
    if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY)
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   279
        BAIL_IF(fsync(fd) == -1, errcodeFromErrno(), 0);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   280
    return 1;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
} /* __PHYSFS_platformFlush */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   284
void __PHYSFS_platformClose(void *opaque)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
{
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   286
    const int fd = *((int *) opaque);
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   287
    (void) close(fd);  /* we don't check this. You should have used flush! */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   288
    allocator.Free(opaque);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
} /* __PHYSFS_platformClose */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
int __PHYSFS_platformDelete(const char *path)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
{
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   294
    BAIL_IF(remove(path) == -1, errcodeFromErrno(), 0);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   295
    return 1;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
} /* __PHYSFS_platformDelete */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 235
diff changeset
   298
1327
998351d485d9 Cleaned out the "exists" nonsense in the stat() API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1324
diff changeset
   299
int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st)
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   300
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   301
    struct stat statbuf;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   302
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   303
    BAIL_IF(lstat(filename, &statbuf) == -1, errcodeFromErrno(), 0);
1167
9d84f8652839 POSIX version of __PHYSFS_platformStat() forgot to set *exists properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   304
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   305
    if (S_ISREG(statbuf.st_mode))
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   306
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   307
        st->filetype = PHYSFS_FILETYPE_REGULAR;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   308
        st->filesize = statbuf.st_size;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   309
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   310
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   311
    else if(S_ISDIR(statbuf.st_mode))
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   312
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   313
        st->filetype = PHYSFS_FILETYPE_DIRECTORY;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   314
        st->filesize = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   315
    } /* else if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   316
1323
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   317
    else if(S_ISLNK(statbuf.st_mode))
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   318
    {
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   319
        st->filetype = PHYSFS_FILETYPE_SYMLINK;
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   320
        st->filesize = 0;
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   321
    } /* else if */
61ca5d6011df POSIX version of __PHYSFS_platformStat() now reports symlinks correctly.
Ryan C. Gordon <icculus@icculus.org>
parents: 1322
diff changeset
   322
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   323
    else
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   324
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   325
        st->filetype = PHYSFS_FILETYPE_OTHER;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   326
        st->filesize = statbuf.st_size;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   327
    } /* else */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   328
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   329
    st->modtime = statbuf.st_mtime;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   330
    st->createtime = statbuf.st_ctime;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   331
    st->accesstime = statbuf.st_atime;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   332
1543
210b82b60730 Removed some FIXMEs that aren't valid.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
   333
    st->readonly = (access(filename, W_OK) == -1);
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1098
diff changeset
   334
    return 1;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   335
} /* __PHYSFS_platformStat */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   336
1173
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   337
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   338
typedef struct
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   339
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   340
    pthread_mutex_t mutex;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   341
    pthread_t owner;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   342
    PHYSFS_uint32 count;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   343
} PthreadMutex;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   344
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   345
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   346
void *__PHYSFS_platformGetThreadID(void)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   347
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   348
    return ( (void *) ((size_t) pthread_self()) );
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   349
} /* __PHYSFS_platformGetThreadID */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   350
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   351
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   352
void *__PHYSFS_platformCreateMutex(void)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   353
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   354
    int rc;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   355
    PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex));
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   356
    BAIL_IF(!m, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
1173
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   357
    rc = pthread_mutex_init(&m->mutex, NULL);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   358
    if (rc != 0)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   359
    {
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   360
        allocator.Free(m);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1335
diff changeset
   361
        BAIL(PHYSFS_ERR_OS_ERROR, NULL);
1173
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   362
    } /* if */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   363
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   364
    m->count = 0;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   365
    m->owner = (pthread_t) 0xDEADBEEF;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   366
    return ((void *) m);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   367
} /* __PHYSFS_platformCreateMutex */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   368
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   369
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   370
void __PHYSFS_platformDestroyMutex(void *mutex)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   371
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   372
    PthreadMutex *m = (PthreadMutex *) mutex;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   373
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   374
    /* Destroying a locked mutex is a bug, but we'll try to be helpful. */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   375
    if ((m->owner == pthread_self()) && (m->count > 0))
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   376
        pthread_mutex_unlock(&m->mutex);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   377
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   378
    pthread_mutex_destroy(&m->mutex);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   379
    allocator.Free(m);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   380
} /* __PHYSFS_platformDestroyMutex */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   381
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   382
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   383
int __PHYSFS_platformGrabMutex(void *mutex)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   384
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   385
    PthreadMutex *m = (PthreadMutex *) mutex;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   386
    pthread_t tid = pthread_self();
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   387
    if (m->owner != tid)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   388
    {
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   389
        if (pthread_mutex_lock(&m->mutex) != 0)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   390
            return 0;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   391
        m->owner = tid;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   392
    } /* if */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   393
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   394
    m->count++;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   395
    return 1;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   396
} /* __PHYSFS_platformGrabMutex */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   397
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   398
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   399
void __PHYSFS_platformReleaseMutex(void *mutex)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   400
{
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   401
    PthreadMutex *m = (PthreadMutex *) mutex;
1238
97d4522cdf02 Check for mutex bugs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1228
diff changeset
   402
    assert(m->owner == pthread_self());  /* catch programming errors. */
97d4522cdf02 Check for mutex bugs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1228
diff changeset
   403
    assert(m->count > 0);  /* catch programming errors. */
1173
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   404
    if (m->owner == pthread_self())
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   405
    {
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   406
        if (--m->count == 0)
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   407
        {
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   408
            m->owner = (pthread_t) 0xDEADBEEF;
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   409
            pthread_mutex_unlock(&m->mutex);
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   410
        } /* if */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   411
    } /* if */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   412
} /* __PHYSFS_platformReleaseMutex */
77b2df665bd1 Removed deprecated Mac OS X APIs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1167
diff changeset
   413
818
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   414
#endif  /* PHYSFS_PLATFORM_POSIX */
310
f8bca4a93fd5 Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 292
diff changeset
   415
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   416
/* end of physfs_platform_posix.c ... */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417