archivers/dir.c
changeset 23 bd6ba9c8717c
parent 22 49f6101707b4
child 28 529214f57d1b
equal deleted inserted replaced
22:49f6101707b4 23:bd6ba9c8717c
   105 } /* DIR_isArchive */
   105 } /* DIR_isArchive */
   106 
   106 
   107 
   107 
   108 static DirHandle *DIR_openArchive(const char *name, int forWriting)
   108 static DirHandle *DIR_openArchive(const char *name, int forWriting)
   109 {
   109 {
   110     const char *dirsep = __PHYSFS_platformDirSeparator;
   110     const char *dirsep = PHYSFS_getDirSeparator();
   111     DirHandle *retval = NULL;
   111     DirHandle *retval = NULL;
   112     int namelen = strlen(name);
   112     int namelen = strlen(name);
   113     int seplen = strlen(dirsep);
   113     int seplen = strlen(dirsep);
   114 
   114 
   115     BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
   115     BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
   119     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   119     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   120     retval->opaque = malloc(namelen + seplen + 1);
   120     retval->opaque = malloc(namelen + seplen + 1);
   121     if (retval->opaque == NULL)
   121     if (retval->opaque == NULL)
   122     {
   122     {
   123         free(retval);
   123         free(retval);
   124         BAIL_IF_MACRO(0, ERR_OUT_OF_MEMORY, NULL);
   124         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
   125     } /* if */
   125     } /* if */
   126 
   126 
   127         /* make sure there's a dir separator at the end of the string */
   127         /* make sure there's a dir separator at the end of the string */
   128     strcpy((char *) (retval->opaque), name);
   128     strcpy((char *) (retval->opaque), name);
   129     if (strcmp((name + namelen) - seplen, dirsep) != 0)
   129     if (strcmp((name + namelen) - seplen, dirsep) != 0)
   193 
   193 
   194     retval = (FileHandle *) malloc(sizeof (FileHandle));
   194     retval = (FileHandle *) malloc(sizeof (FileHandle));
   195     if (!retval)
   195     if (!retval)
   196     {
   196     {
   197         free(f);
   197         free(f);
   198         BAIL_IF_MACRO(0, ERR_OUT_OF_MEMORY, NULL);
   198         BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
   199     } /* if */
   199     } /* if */
   200 
   200 
   201     errno = 0;
   201     errno = 0;
   202     rc = fopen(f, mode);
   202     rc = fopen(f, mode);
   203     str = strerror(errno);
   203     str = strerror(errno);
   204     free(f);
   204     free(f);
   205 
   205 
   206     if (!rc)
   206     if (!rc)
   207     {
   207     {
   208         free(retval);
   208         free(retval);
   209         BAIL_IF_MACRO(0, str, NULL);
   209         BAIL_IF_MACRO(1, str, NULL);
   210     } /* if */
   210     } /* if */
   211 
   211 
   212     retval->opaque = (void *) rc;
   212     retval->opaque = (void *) rc;
   213     retval->dirHandle = h;
   213     retval->dirHandle = h;
   214     retval->funcs = &__PHYSFS_FileFunctions_DIR;
   214     retval->funcs = &__PHYSFS_FileFunctions_DIR;