X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=misc.c;h=29ba73985ff4711753948c2965133aea6ffbe2c0;hb=69dd06bfd7bb894e0683361aa3fb9ce35ade3590;hp=0a58cb96be67593103343ca25c032674321f3f06;hpb=0d3c17d9ab127e5596c8fb97d65122b3b90f6b11;p=pkg%2Fabook.git diff --git a/misc.c b/misc.c index 0a58cb9..29ba739 100644 --- a/misc.c +++ b/misc.c @@ -1,7 +1,8 @@ /* - * misc.c - * by JH + * $Id$ + * + * by JH * * Copyright (C) Jaakko Heinonen */ @@ -15,6 +16,9 @@ #include #include #include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include "misc.h" #ifdef ABOOK_SRC # include "abook.h" @@ -122,10 +126,13 @@ mkstr (const char *format, ... ) format, ap); MY_VA_END; - if (n > -1) + if (n > -1 && n < size) return buffer; - size *= 2; + if (n > -1) + size = n + 1; + else + size *= 2; buffer = #ifdef ABOOK_SRC @@ -177,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; @@ -186,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() { @@ -228,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);