physfs.c
changeset 578 bff1af8455ca
parent 576 5da65f8e9a50
child 582 d15d27e34a7e
equal deleted inserted replaced
577:90a06832dcf3 578:bff1af8455ca
   163 {
   163 {
   164     PHYSFS_uint32 i;
   164     PHYSFS_uint32 i;
   165     PHYSFS_uint32 j;
   165     PHYSFS_uint32 j;
   166     PHYSFS_uint32 v;
   166     PHYSFS_uint32 v;
   167 
   167 
   168 	if ((hi - lo) <= PHYSFS_QUICKSORT_THRESHOLD)
   168     if ((hi - lo) <= PHYSFS_QUICKSORT_THRESHOLD)
   169         __PHYSFS_bubble_sort(a, lo, hi, cmpfn, swapfn);
   169         __PHYSFS_bubble_sort(a, lo, hi, cmpfn, swapfn);
   170     else
   170     else
   171 	{
   171     {
   172 		i = (hi + lo) / 2;
   172         i = (hi + lo) / 2;
   173 
   173 
   174         if (cmpfn(a, lo, i) > 0) swapfn(a, lo, i);
   174         if (cmpfn(a, lo, i) > 0) swapfn(a, lo, i);
   175 		if (cmpfn(a, lo, hi) > 0) swapfn(a, lo, hi);
   175         if (cmpfn(a, lo, hi) > 0) swapfn(a, lo, hi);
   176 		if (cmpfn(a, i, hi) > 0) swapfn(a, i, hi);
   176         if (cmpfn(a, i, hi) > 0) swapfn(a, i, hi);
   177 
   177 
   178 		j = hi - 1;
   178         j = hi - 1;
   179 		swapfn(a, i, j);
   179         swapfn(a, i, j);
   180 		i = lo;
   180         i = lo;
   181 		v = j;
   181         v = j;
   182 		while (1)
   182         while (1)
   183 		{
   183         {
   184 			while(cmpfn(a, ++i, v) < 0) { /* do nothing */ }
   184             while(cmpfn(a, ++i, v) < 0) { /* do nothing */ }
   185 			while(cmpfn(a, --j, v) > 0) { /* do nothing */ }
   185             while(cmpfn(a, --j, v) > 0) { /* do nothing */ }
   186 			if (j < i)
   186             if (j < i)
   187                 break;
   187                 break;
   188 			swapfn(a, i, j);
   188             swapfn(a, i, j);
   189 		} /* while */
   189         } /* while */
   190 		swapfn(a, i, hi-1);
   190         swapfn(a, i, hi-1);
   191 		__PHYSFS_quick_sort(a, lo, j, cmpfn, swapfn);
   191         __PHYSFS_quick_sort(a, lo, j, cmpfn, swapfn);
   192 		__PHYSFS_quick_sort(a, i+1, hi, cmpfn, swapfn);
   192         __PHYSFS_quick_sort(a, i+1, hi, cmpfn, swapfn);
   193 	} /* else */
   193     } /* else */
   194 } /* __PHYSFS_quick_sort */
   194 } /* __PHYSFS_quick_sort */
   195 
   195 
   196 
   196 
   197 void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
   197 void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
   198                    int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
   198                    int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32),
   673     /*
   673     /*
   674      * Last ditch effort: it's the current working directory. (*shrug*)
   674      * Last ditch effort: it's the current working directory. (*shrug*)
   675      */
   675      */
   676     retval = __PHYSFS_platformCurrentDir();
   676     retval = __PHYSFS_platformCurrentDir();
   677     if(retval != NULL) {
   677     if(retval != NULL) {
   678 	return(retval);
   678     return(retval);
   679     }
   679     }
   680 
   680 
   681     /*
   681     /*
   682      * Ok, current directory doesn't exist, use the root directory.
   682      * Ok, current directory doesn't exist, use the root directory.
   683      * Not a good alternative, but it only happens if the current
   683      * Not a good alternative, but it only happens if the current
  1849 
  1849 
  1850 
  1850 
  1851 int PHYSFS_setBuffer(PHYSFS_file *handle, PHYSFS_uint64 _bufsize)
  1851 int PHYSFS_setBuffer(PHYSFS_file *handle, PHYSFS_uint64 _bufsize)
  1852 {
  1852 {
  1853     FileHandle *h = (FileHandle *) handle->opaque;
  1853     FileHandle *h = (FileHandle *) handle->opaque;
  1854 	PHYSFS_uint32 bufsize = (PHYSFS_uint32) _bufsize;
  1854     PHYSFS_uint32 bufsize = (PHYSFS_uint32) _bufsize;
  1855 
  1855 
  1856     BAIL_IF_MACRO(_bufsize > 0xFFFFFFFF, "buffer must fit in 32-bits", 0);
  1856     BAIL_IF_MACRO(_bufsize > 0xFFFFFFFF, "buffer must fit in 32-bits", 0);
  1857     BAIL_IF_MACRO(!PHYSFS_flush(handle), NULL, 0);
  1857     BAIL_IF_MACRO(!PHYSFS_flush(handle), NULL, 0);
  1858 
  1858 
  1859     /*
  1859     /*