src/archiver_dir.c
changeset 1240 22d4d1bd4e21
parent 1226 3ea51c799aba
child 1241 86dd9db48c76
equal deleted inserted replaced
1239:a96d88b357bc 1240:22d4d1bd4e21
    13 
    13 
    14 
    14 
    15 
    15 
    16 static char *cvtToDependent(const char *prepend, const char *path, char *buf)
    16 static char *cvtToDependent(const char *prepend, const char *path, char *buf)
    17 {
    17 {
    18     BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, NULL);
    18     BAIL_IF_MACRO(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
    19     sprintf(buf, "%s%s", prepend ? prepend : "", path);
    19     sprintf(buf, "%s%s", prepend ? prepend : "", path);
    20 
    20 
    21     if (__PHYSFS_platformDirSeparator != '/')
    21     if (__PHYSFS_platformDirSeparator != '/')
    22     {
    22     {
    23         char *p;
    23         char *p;
    36 
    36 
    37 
    37 
    38 
    38 
    39 static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
    39 static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
    40 {
    40 {
    41     PHYSFS_Stat statbuf;
    41     PHYSFS_Stat st;
    42     const char dirsep = __PHYSFS_platformDirSeparator;
    42     const char dirsep = __PHYSFS_platformDirSeparator;
    43     char *retval = NULL;
    43     char *retval = NULL;
    44     const size_t namelen = strlen(name);
    44     const size_t namelen = strlen(name);
    45     const size_t seplen = 1;
    45     const size_t seplen = 1;
    46     int exists = 0;
    46     int exists = 0;
    47 
    47 
    48     assert(io == NULL);  /* shouldn't create an Io for these. */
    48     assert(io == NULL);  /* shouldn't create an Io for these. */
    49     BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &statbuf), NULL, NULL);
    49     BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &st), ERRPASS, NULL);
    50     if ((!exists) || (statbuf.filetype != PHYSFS_FILETYPE_DIRECTORY))
    50     /* !!! FIXME: the failed Stat() call will BAIL before we check (exists) */
    51         BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL);
    51     /* !!! FIXME:  ...should we even be checking for existance here...? */
       
    52     BAIL_IF_MACRO(!exists, PHYSFS_ERR_NO_SUCH_PATH, NULL);
       
    53     if (st.filetype != PHYSFS_FILETYPE_DIRECTORY)
       
    54         BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
    52 
    55 
    53     retval = allocator.Malloc(namelen + seplen + 1);
    56     retval = allocator.Malloc(namelen + seplen + 1);
    54     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
    57     BAIL_IF_MACRO(retval == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
    55 
    58 
    56     strcpy(retval, name);
    59     strcpy(retval, name);
    57 
    60 
    58     /* make sure there's a dir separator at the end of the string */
    61     /* make sure there's a dir separator at the end of the string */
    59     if (retval[namelen - 1] != dirsep)
    62     if (retval[namelen - 1] != dirsep)
    88     char *f;
    91     char *f;
    89     PHYSFS_Io *io = NULL;
    92     PHYSFS_Io *io = NULL;
    90     int existtmp = 0;
    93     int existtmp = 0;
    91 
    94 
    92     CVT_TO_DEPENDENT(f, opaque, name);
    95     CVT_TO_DEPENDENT(f, opaque, name);
    93     BAIL_IF_MACRO(f == NULL, NULL, NULL);
    96     BAIL_IF_MACRO(!f, ERRPASS, NULL);
    94 
    97 
    95     if (fileExists == NULL)
    98     if (fileExists == NULL)
    96         fileExists = &existtmp;
    99         fileExists = &existtmp;
    97 
   100 
    98     io = __PHYSFS_createNativeIo(f, mode);
   101     io = __PHYSFS_createNativeIo(f, mode);
   134 {
   137 {
   135     int retval;
   138     int retval;
   136     char *f;
   139     char *f;
   137 
   140 
   138     CVT_TO_DEPENDENT(f, opaque, name);
   141     CVT_TO_DEPENDENT(f, opaque, name);
   139     BAIL_IF_MACRO(f == NULL, NULL, 0);
   142     BAIL_IF_MACRO(!f, ERRPASS, 0);
   140     retval = __PHYSFS_platformDelete(f);
   143     retval = __PHYSFS_platformDelete(f);
   141     __PHYSFS_smallFree(f);
   144     __PHYSFS_smallFree(f);
   142     return retval;
   145     return retval;
   143 } /* DIR_remove */
   146 } /* DIR_remove */
   144 
   147 
   147 {
   150 {
   148     int retval;
   151     int retval;
   149     char *f;
   152     char *f;
   150 
   153 
   151     CVT_TO_DEPENDENT(f, opaque, name);
   154     CVT_TO_DEPENDENT(f, opaque, name);
   152     BAIL_IF_MACRO(f == NULL, NULL, 0);
   155     BAIL_IF_MACRO(!f, ERRPASS, 0);
   153     retval = __PHYSFS_platformMkDir(f);
   156     retval = __PHYSFS_platformMkDir(f);
   154     __PHYSFS_smallFree(f);
   157     __PHYSFS_smallFree(f);
   155     return retval;
   158     return retval;
   156 } /* DIR_mkdir */
   159 } /* DIR_mkdir */
   157 
   160 
   167 {
   170 {
   168     int retval = 0;
   171     int retval = 0;
   169     char *d;
   172     char *d;
   170 
   173 
   171     CVT_TO_DEPENDENT(d, opaque, name);
   174     CVT_TO_DEPENDENT(d, opaque, name);
   172     BAIL_IF_MACRO(d == NULL, NULL, 0);
   175     BAIL_IF_MACRO(!d, ERRPASS, 0);
   173     retval = __PHYSFS_platformStat(d, exists, stat);
   176     retval = __PHYSFS_platformStat(d, exists, stat);
   174     __PHYSFS_smallFree(d);
   177     __PHYSFS_smallFree(d);
   175     return retval;
   178     return retval;
   176 } /* DIR_stat */
   179 } /* DIR_stat */
   177 
   180