physfs.c
changeset 668 a5c80bd9549e
parent 663 65132f8a8692
child 679 ae75b5548364
equal deleted inserted replaced
666:7ca5dede89f2 668:a5c80bd9549e
  1303                               char **list,
  1303                               char **list,
  1304                               PHYSFS_uint32 *pos)
  1304                               PHYSFS_uint32 *pos)
  1305 {
  1305 {
  1306     PHYSFS_uint32 hi = *pos - 1;
  1306     PHYSFS_uint32 hi = *pos - 1;
  1307     PHYSFS_uint32 lo = 0;
  1307     PHYSFS_uint32 lo = 0;
  1308     PHYSFS_uint32 i = hi / 2;
  1308     PHYSFS_uint32 i = hi >> 1;
  1309     int cmp;
  1309     int cmp;
       
  1310 
       
  1311     assert(*pos != 0);  /* this doesn't work with empty lists! */
  1310 
  1312 
  1311     while (hi != lo)
  1313     while (hi != lo)
  1312     {
  1314     {
  1313         cmp = strcmp(list[i], str);
  1315         cmp = strcmp(list[i], str);
  1314         if (cmp == 0)  /* it's in the list already. */
  1316         if (cmp == 0)  /* it's in the list already. */
  1315             return(1);
  1317             return(1);
  1316         else if (cmp < 0)
  1318         else if (cmp < 0)
       
  1319         {
  1317             hi = i;
  1320             hi = i;
       
  1321             i = lo + ((hi - lo) >> 1);
       
  1322         } /* else if */
  1318         else
  1323         else
  1319             lo = i;
  1324         {
  1320         i = lo + ((hi - lo) / 2);
  1325             lo = i + 1;
       
  1326             i = lo + ((1 + hi - lo) >> 1);
       
  1327         } /* else */
  1321     } /* while */
  1328     } /* while */
  1322 
  1329 
  1323     /* hi == lo, check it in case it's the match... */
  1330     /* hi == lo, check it in case it's the match... */
  1324     cmp = strcmp(list[lo], str);
  1331     cmp = strcmp(list[lo], str);
  1325     if (cmp == 0)
  1332     if (cmp == 0)