summaryrefslogtreecommitdiffstats
path: root/lib/libmytinfo/compar.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libmytinfo/compar.c')
-rw-r--r--lib/libmytinfo/compar.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/libmytinfo/compar.c b/lib/libmytinfo/compar.c
new file mode 100644
index 0000000..f8998d3
--- /dev/null
+++ b/lib/libmytinfo/compar.c
@@ -0,0 +1,40 @@
+/*
+ * compar.c
+ *
+ * By Ross Ridge
+ * Public Domain
+ * 92/06/04 11:36:24
+ *
+ */
+
+#include "defs.h"
+
+#ifdef USE_SCCS_IDS
+static const char SCCSid[] = "@(#) mytinfo compar.c 3.3 92/06/04 public domain, By Ross Ridge";
+#endif
+
+/* compare two elements a sorted list of pointers to strings */
+int
+_compar(a, b)
+#ifdef USE_ANSIC
+void const *a;
+void const *b; {
+#else
+anyptr a, b; {
+#endif
+ register char *aa = **(char ***)a;
+ register char *bb = **(char ***)b;
+
+ /* An optimization trick from C News, compare the first
+ * two chars of the string here to avoid a the overhead of a
+ * call to strcmp.
+ */
+
+#ifdef __GNUC__
+ return ((*aa - *bb) ? : strcmp(aa, bb));
+#else
+ if (*aa != *bb)
+ return *aa - *bb;
+ return strcmp(aa, bb);
+#endif
+}
OpenPOWER on IntegriCloud