]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/qsort.c
Intermediate work, checked in for safekeeping as I pick up working on this again.
[pdclib] / functions / stdlib / qsort.c
index fedda0f58f710e851f3d2151cc9d668ecceb9c20..6bb636f5631d5c50a51f9052c9b947f61507fb49 100644 (file)
@@ -1,7 +1,5 @@
 /* $Id$ */
 
-/* Release $Name$ */
-
 /* qsort( void *, size_t, size_t, int(*)( const void *, const void * ) )
 
    This file is part of the Public Domain C Library (PDCLib).
@@ -21,7 +19,7 @@
 */
 
 /* Wrapper for _PDCLIB_memswp protects against multiple argument evaluation. */
-static inline void memswp( char * i, char * j, unsigned int size )
+static inline void memswp( char * i, char * j, size_t size )
 {
     _PDCLIB_memswp( i, j, size );
 }
@@ -43,9 +41,9 @@ void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *,
 {
     char * i;
     char * j;
-    size_t thresh     = T * size;
-    char * base_      = (char *)base;
-    char * limit      = base_ + nmemb * size;
+    _PDCLIB_ptrdiff_t thresh  = T * size;
+    char * base_              = (char *)base;
+    char * limit              = base_ + nmemb * size;
     PREPARE_STACK;
 
     for ( ;; )
@@ -133,18 +131,17 @@ void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *,
 #include <string.h>
 #include <limits.h>
 
-int compare( const void * left, const void * right )
+static int compare( const void * left, const void * right )
 {
     return *( (unsigned char *)left ) - *( (unsigned char *)right );
 }
 
-int main()
+int main( void )
 {
     char presort[] = { "shreicnyjqpvozxmbt" };
     char sorted1[] = { "bcehijmnopqrstvxyz" };
     char sorted2[] = { "bticjqnyozpvreshxm" };
     char s[19];
-    BEGIN_TESTS;
     strcpy( s, presort );
     qsort( s, 18, 1, compare );
     TESTCASE( strcmp( s, sorted1 ) == 0 );