OSSP CVS Repository

ossp - Difference in ossp-pkg/fsl/fsl.c versions 1.62 and 1.63
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/fsl/fsl.c 1.62 -> 1.63

--- fsl.c        2003/10/10 14:07:49     1.62
+++ fsl.c        2003/10/13 13:18:28     1.63
@@ -371,22 +371,21 @@
     return rc;
 }
 
-/* alphabetically compare one string with another, to use with qsort(3) */
+/* alphabetically compare two filenames, use with qsort(3) */
 static int fnamecmp(const void *str1, const void *str2)
 {
-    /* because the end goal is to sort an array of strings in alphabetical */
-    /* decending order, tailor the bahaviour of this compare method to     */
-    /* account for null strings that should go at the end of the array     */
-    if (*(const char **)str1) {
-        if (*(const char **)str2)
-            return strcmp(*(const char **)str1, *(const char **)str2);
-        else
-            return (-1); /* only str2 was null, so str1 is lesser by default */
-    }
-    else if (*(const char **)str2)
-        return (1); /* only str1 was null, so str2 is lesser by default */
-    else
-        return (0); /* both str1 and str2 were null, so they are equal */
+    if ((*(const char **)str1 != NULL) && (*(const char **)str2 != NULL))
+        return strcmp(*(const char **)str1, *(const char **)str2);
+
+    /* this must never happen but be prepared for the impossible */
+
+    if ((*(const char **)str1 != NULL) && (*(const char **)str2 == NULL))
+        return strcmp(*(const char **)str1, "");
+
+    if ((*(const char **)str1 == NULL) && (*(const char **)str2 != NULL))
+        return strcmp("", *(const char **)str1);
+
+    return strcmp("", "");
 }
 
 /* read all possible files "fsl.*" into buffer */

CVSTrac 2.0.1