physfs.c
changeset 51 42f4befc1d0b
parent 48 113df08e5fee
child 57 1ec888db3df9
equal deleted inserted replaced
50:989b413188e5 51:42f4befc1d0b
   520 } /* PHYSFS_setWriteDir */
   520 } /* PHYSFS_setWriteDir */
   521 
   521 
   522 
   522 
   523 int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
   523 int PHYSFS_addToSearchPath(const char *newDir, int appendToPath)
   524 {
   524 {
   525     DirInfo *di = buildDirInfo(newDir, 0);
   525     DirInfo *di;
       
   526     DirInfo *i = searchPath;
       
   527     DirInfo *prev = NULL;
       
   528 
       
   529     while (i != NULL)
       
   530     {
       
   531         if (strcmp(newDir, i->dirName) == 0)  /* already in search path. */
       
   532             return(1);
       
   533 
       
   534         prev = i;
       
   535         i = i->next;
       
   536     } /* while */
       
   537 
       
   538     di = buildDirInfo(newDir, 0);
   526 
   539 
   527     BAIL_IF_MACRO(di == NULL, NULL, 0);
   540     BAIL_IF_MACRO(di == NULL, NULL, 0);
   528 
   541 
   529     if (appendToPath)
   542     if (appendToPath)
   530     {
   543     {
   531         DirInfo *i = searchPath;
       
   532         DirInfo *prev = NULL;
       
   533 
       
   534         di->next = NULL;
   544         di->next = NULL;
   535         while (i != NULL)
       
   536         {
       
   537             prev = i;
       
   538             i = i->next;
       
   539         } /* while */
       
   540 
       
   541         if (prev == NULL)
   545         if (prev == NULL)
   542             searchPath = di;
   546             searchPath = di;
   543         else
   547         else
   544             prev->next = di;
   548             prev->next = di;
   545     } /* if */
   549     } /* if */
  1145 } /* PHYSFS_openAppend */
  1149 } /* PHYSFS_openAppend */
  1146 
  1150 
  1147 
  1151 
  1148 PHYSFS_file *PHYSFS_openRead(const char *fname)
  1152 PHYSFS_file *PHYSFS_openRead(const char *fname)
  1149 {
  1153 {
  1150     PHYSFS_file *retval = NULL;
       
  1151     FileHandle *rc = NULL;
  1154     FileHandle *rc = NULL;
  1152     FileHandleList *list;
  1155     FileHandleList *list;
  1153     DirInfo *i;
  1156     DirInfo *i;
  1154 
  1157 
  1155     while (*fname == '/')
  1158     while (*fname == '/')
  1156         fname++;
  1159         fname++;
  1157 
       
  1158     list = (FileHandleList *) malloc(sizeof (FileHandleList));
       
  1159     BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
       
  1160 
  1160 
  1161     for (i = searchPath; i != NULL; i = i->next)
  1161     for (i = searchPath; i != NULL; i = i->next)
  1162     {
  1162     {
  1163         DirHandle *h = i->dirHandle;
  1163         DirHandle *h = i->dirHandle;
  1164         if (__PHYSFS_verifySecurity(h, fname))
  1164         if (__PHYSFS_verifySecurity(h, fname))
  1168                 break;
  1168                 break;
  1169         } /* if */
  1169         } /* if */
  1170     } /* for */
  1170     } /* for */
  1171 
  1171 
  1172     if (rc == NULL)
  1172     if (rc == NULL)
  1173         free(list);
  1173         return(NULL);
  1174     else
  1174 
  1175     {
  1175     list = (FileHandleList *) malloc(sizeof (FileHandleList));
  1176         list->handle.opaque = (void *) rc;
  1176     BAIL_IF_MACRO(!list, ERR_OUT_OF_MEMORY, NULL);
  1177         list->next = openReadList;
  1177     list->handle.opaque = (void *) rc;
  1178         openReadList = list;
  1178     list->next = openReadList;
  1179         retval = &(list->handle);
  1179     openReadList = list;
  1180     } /* else */
  1180 
  1181 
  1181     return(&(list->handle));
  1182     return(retval);
       
  1183 } /* PHYSFS_openRead */
  1182 } /* PHYSFS_openRead */
  1184 
  1183 
  1185 
  1184 
  1186 static int closeHandleInOpenList(FileHandleList **list, PHYSFS_file *handle)
  1185 static int closeHandleInOpenList(FileHandleList **list, PHYSFS_file *handle)
  1187 {
  1186 {