physfs.c
changeset 550 2116f9dc14bc
parent 549 1282b8cbfc0b
child 553 4338d9c0bbcd
equal deleted inserted replaced
549:1282b8cbfc0b 550:2116f9dc14bc
  1230                 free(str);
  1230                 free(str);
  1231                 return(0); /* insecure. */
  1231                 return(0); /* insecure. */
  1232             } /* if */
  1232             } /* if */
  1233 
  1233 
  1234             /* break out early if path element is missing. */
  1234             /* break out early if path element is missing. */
  1235             if ((!retval) && (!allowMissing))
  1235             if (!retval)
  1236             {
  1236             {
  1237                 /*
  1237                 /*
  1238                  * We need to clear it if it's the last element of the path,
  1238                  * We need to clear it if it's the last element of the path,
  1239                  *  since this might be a non-existant file we're opening
  1239                  *  since this might be a non-existant file we're opening
  1240                  *  for writing...
  1240                  *  for writing...
  1241                  */
  1241                  */
  1242                 if (end == NULL)
  1242                 if ((end == NULL) || (allowMissing))
  1243                     retval = 1;
  1243                     retval = 1;
  1244                 break;
  1244                 break;
  1245             } /* if */
  1245             } /* if */
  1246         } /* if */
  1246         } /* if */
  1247 
  1247 
  1262     DirHandle *h;
  1262     DirHandle *h;
  1263     char *str;
  1263     char *str;
  1264     char *start;
  1264     char *start;
  1265     char *end;
  1265     char *end;
  1266     int retval = 0;
  1266     int retval = 0;
       
  1267     int exists = 1;  /* force existance check on first path element. */
  1267 
  1268 
  1268     BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0);
  1269     BAIL_IF_MACRO(dname == NULL, ERR_INVALID_ARGUMENT, 0);
  1269     while (*dname == '/')
  1270     while (*dname == '/')
  1270         dname++;
  1271         dname++;
  1271 
  1272 
  1277     BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
  1278     BAIL_IF_MACRO_MUTEX(str == NULL, ERR_OUT_OF_MEMORY, stateLock, 0);
  1278     strcpy(str, dname);
  1279     strcpy(str, dname);
  1279 
  1280 
  1280     while (1)
  1281     while (1)
  1281     {
  1282     {
  1282         int already_exists;
       
  1283 
       
  1284         end = strchr(start, '/');
  1283         end = strchr(start, '/');
  1285         if (end != NULL)
  1284         if (end != NULL)
  1286             *end = '\0';
  1285             *end = '\0';
  1287 
  1286 
  1288         retval = h->funcs->isDirectory(h, str, &already_exists);
  1287         /* only check for existance if all parent dirs existed, too... */
  1289         if ((!retval) && (!already_exists))
  1288         if (exists)
       
  1289             retval = h->funcs->isDirectory(h, str, &exists);
       
  1290 
       
  1291         if (!exists)
  1290             retval = h->funcs->mkdir(h, str);
  1292             retval = h->funcs->mkdir(h, str);
  1291 
  1293 
  1292         if (!retval)
  1294         if (!retval)
  1293             break;
  1295             break;
  1294 
  1296