]> git.deb.at Git - pkg/abook.git/blobdiff - misc.c
use strcoll instead of strcmp for sorting entries
[pkg/abook.git] / misc.c
diff --git a/misc.c b/misc.c
index 1213dd57297d734797f3cc1c6d5ab3de91b1e2e1..29ba73985ff4711753948c2965133aea6ffbe2c0 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -2,7 +2,7 @@
 /*
  * $Id$
  *
- * by JH <jheinonen@bigfoot.com>
+ * by JH <jheinonen@users.sourceforge.net>
  *
  * Copyright (C) Jaakko Heinonen
  */
@@ -16,6 +16,9 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <errno.h>
+#ifdef HAVE_CONFIG_H
+#      include "config.h"
+#endif
 #include "misc.h"
 #ifdef ABOOK_SRC
 #      include "abook.h"
@@ -181,7 +184,7 @@ strconcat (const char *str, ...)
 
 
 int
-safe_strcmp(const char *s1, const char * s2)
+safe_strcmp(const char *s1, const char *s2)
 {
        if (s1 == NULL && s2 == NULL) return 0;
        if (s1 == NULL) return -1;
@@ -190,6 +193,20 @@ safe_strcmp(const char *s1, const char * s2)
        return strcmp(s1, s2);
 }
 
+int
+safe_strcoll(const char *s1, const char *s2)
+{
+#ifdef HAVE_STRCOLL
+       if (s1 == NULL && s2 == NULL) return 0;
+       if (s1 == NULL) return -1;
+       if (s2 == NULL) return 1;
+
+       return strcoll(s1, s2);
+#else /* fall back to strcmp */
+       return safe_strcmp(s1, s2);
+#endif
+}
+
 char *
 my_getcwd()
 {
@@ -232,7 +249,7 @@ getaline(FILE *f)
 
        len = 0;
        size = thres;
-       buf = abook_malloc(size);
+       buf = (char *)abook_malloc(size);
 
        while (fgets(buf+len, size-len, f) != NULL) {
                len += strlen(buf+len);