physfs.c
changeset 20 efdde0d21521
parent 19 a0279b57398c
child 21 b1ea58d70a56
equal deleted inserted replaced
19:a0279b57398c 20:efdde0d21521
   192     dirHandle = openDirectory(newDir, forWriting);
   192     dirHandle = openDirectory(newDir, forWriting);
   193     BAIL_IF_MACRO(dirHandle == NULL, NULL, 0);
   193     BAIL_IF_MACRO(dirHandle == NULL, NULL, 0);
   194 
   194 
   195     di = (DirInfo *) malloc(sizeof (DirInfo));
   195     di = (DirInfo *) malloc(sizeof (DirInfo));
   196     if (di == NULL)
   196     if (di == NULL)
   197         dirHandle->funcs->close(dirHandle);
   197         dirHandle->funcs->dirClose(dirHandle);
   198     BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
   198     BAIL_IF_MACRO(di == NULL, ERR_OUT_OF_MEMORY, 0);
   199 
   199 
   200     di->dirName = (char *) malloc(strlen(newDir) + 1);
   200     di->dirName = (char *) malloc(strlen(newDir) + 1);
   201     if (di->dirName == NULL)
   201     if (di->dirName == NULL)
   202     {
   202     {
   203         free(di);
   203         free(di);
   204         dirHandle->funcs->close(dirHandle);
   204         dirHandle->funcs->dirClose(dirHandle);
   205         __PHYSFS_setError(ERR_OUT_OF_MEMORY);
   205         __PHYSFS_setError(ERR_OUT_OF_MEMORY);
   206         return(0);
   206         return(0);
   207     } /* if */
   207     } /* if */
   208 
   208 
   209     di->next = NULL;
   209     di->next = NULL;
   224     {
   224     {
   225         const DirHandle *h = ((FileHandle *) i->handle->opaque)->dirHandle;
   225         const DirHandle *h = ((FileHandle *) i->handle->opaque)->dirHandle;
   226         BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0);
   226         BAIL_IF_MACRO(h == di->dirHandle, ERR_FILES_STILL_OPEN, 0);
   227     } /* for */
   227     } /* for */
   228 
   228 
   229     di->dirHandle->funcs->close(di->dirHandle);
   229     di->dirHandle->funcs->dirClose(di->dirHandle);
   230     free(di->dirName);
   230     free(di->dirName);
   231     free(di);
   231     free(di);
   232     return(1);
   232     return(1);
   233 } /* freeDirInfo */
   233 } /* freeDirInfo */
   234 
   234 
   298 
   298 
   299     for (i = *list; i != NULL; i = next)
   299     for (i = *list; i != NULL; i = next)
   300     {
   300     {
   301         next = i->next;
   301         next = i->next;
   302         h = (FileHandle *) (i->handle->opaque);
   302         h = (FileHandle *) (i->handle->opaque);
   303         if (!h->funcs->close(i->handle->opaque))
   303         if (!h->funcs->fileClose(i->handle->opaque))
   304         {
   304         {
   305             *list = i;
   305             *list = i;
   306             return(0);
   306             return(0);
   307         } /* if */
   307         } /* if */
   308 
   308 
   622     allowSymLinks = allow;
   622     allowSymLinks = allow;
   623 } /* PHYSFS_permitSymbolicLinks */
   623 } /* PHYSFS_permitSymbolicLinks */
   624 
   624 
   625 
   625 
   626 /* string manipulation in C makes my ass itch. */
   626 /* string manipulation in C makes my ass itch. */
   627 char *__PHYSFS_convertToDependentNotation(const char *prepend,
   627 char *__PHYSFS_convertToDependent(const char *prepend,
   628                                           const char *dirName,
   628                                   const char *dirName,
   629                                           const char *append)
   629                                   const char *append)
   630 {
   630 {
   631     const char *dirsep = PHYSFS_getDirSeparator();
   631     const char *dirsep = PHYSFS_getDirSeparator();
   632     int sepsize = strlen(dirsep);
   632     int sepsize = strlen(dirsep);
   633     char *str;
   633     char *str;
   634     char *i1;
   634     char *i1;
   656         } while (str != NULL);
   656         } while (str != NULL);
   657     } /* if */
   657     } /* if */
   658 
   658 
   659     str = (char *) malloc(allocSize);
   659     str = (char *) malloc(allocSize);
   660     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
   660     BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
   661     *str = '\0';
   661 
   662 
   662     if (prepend == NULL)
   663     if (prepend)
   663         *str = '\0';
       
   664     else
   664     {
   665     {
   665         strcpy(str, prepend);
   666         strcpy(str, prepend);
   666         strcat(str, dirsep);
   667         strcat(str, dirsep);
   667     } /* if */
   668     } /* else */
   668 
   669 
   669     for (i1 = (char *) dirName, i2 = str + strlen(str); *i1; i1++, i2++)
   670     for (i1 = (char *) dirName, i2 = str + strlen(str); *i1; i1++, i2++)
   670     {
   671     {
   671         if (*i1 == '/')
   672         if (*i1 == '/')
   672         {
   673         {
   707         if (end != NULL)
   708         if (end != NULL)
   708             *end = '\0';
   709             *end = '\0';
   709 
   710 
   710         if ( (strcmp(start, ".") == 0) ||
   711         if ( (strcmp(start, ".") == 0) ||
   711              (strcmp(start, "..") == 0) ||
   712              (strcmp(start, "..") == 0) ||
       
   713              (strchr(start, '\\') != NULL) ||
   712              (strchr(start, ':') != NULL) )
   714              (strchr(start, ':') != NULL) )
   713         {
   715         {
   714             __PHYSFS_setError(ERR_INSECURE_FNAME);
   716             __PHYSFS_setError(ERR_INSECURE_FNAME);
   715             retval = 0;
   717             retval = 0;
   716             break;
   718             break;
  1056     {
  1058     {
  1057         for (i = *(*lists), prev = NULL; i != NULL; prev = i, i = i->next)
  1059         for (i = *(*lists), prev = NULL; i != NULL; prev = i, i = i->next)
  1058         {
  1060         {
  1059             if (i->handle == handle)
  1061             if (i->handle == handle)
  1060             {
  1062             {
  1061                 rc = h->funcs->close(h);
  1063                 rc = h->funcs->fileClose(h);
  1062                 if (!rc)
  1064                 if (!rc)
  1063                     return(0);
  1065                     return(0);
  1064 
  1066 
  1065                 if (prev == NULL)
  1067                 if (prev == NULL)
  1066                     *(*lists) = i->next;
  1068                     *(*lists) = i->next;