X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=misc.c;h=4bfe3d353cd710f5a5abb4f54fead49c16b888b0;hb=64990eb83b3bab7df8784b6ac1ef540016070e49;hp=8a4b9cfc5d2657fbb8ed69076c849d88b1efa5f6;hpb=efc9a360c599ac2317853a6ff3ca6c3d208b7316;p=pkg%2Fabook.git diff --git a/misc.c b/misc.c index 8a4b9cf..4bfe3d3 100644 --- a/misc.c +++ b/misc.c @@ -19,6 +19,9 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#ifdef HANDLE_MULTIBYTE +# include +#endif #include "misc.h" #ifdef ABOOK_SRC # include "abook.h" @@ -85,12 +88,12 @@ char * mkstr (const char *format, ... ) { MY_VA_LOCAL_DECL; - int size = 100; + size_t size = 100; char *buffer = #ifdef ABOOK_SRC (char *) abook_malloc (size); #else - (char *) malloc (size); + (char *) xmalloc (size); #endif assert(format != NULL); @@ -114,7 +117,7 @@ mkstr (const char *format, ... ) #ifdef ABOOK_SRC (char *) abook_realloc (buffer, size); #else - (char *) realloc (buffer, size); + (char *) xrealloc (buffer, size); #endif } } @@ -142,7 +145,7 @@ strconcat (const char *str, ...) #ifdef ABOOK_SRC abook_malloc(l); #else - malloc(l); + xmalloc(l); #endif if(concat == NULL) return NULL; @@ -188,7 +191,7 @@ char * my_getcwd() { char *dir = NULL; - int size = 100; + size_t size = 100; if( (dir = (char *)malloc(size)) == NULL) return NULL; @@ -204,8 +207,8 @@ my_getcwd() #define INITIAL_SIZE 128 #ifndef ABOOK_SRC -# define abook_malloc(X) malloc(X) -# define abook_realloc(X, XX) realloc(X, XX) +# define abook_malloc(X) xmalloc(X) +# define abook_realloc(X, XX) xrealloc(X, XX) #endif char * @@ -265,6 +268,28 @@ getaline(FILE *f) return buf; } +int +strwidth(const char *s) +{ + assert(s); +#ifdef HANDLE_MULTIBYTE + return (int)mbswidth(s, 0); +#else + return strlen(s); +#endif +} + +int +bytes2width(const char *s, int width) +{ + assert(s); +#ifdef HANDLE_MULTIBYTE + return mbsnbytes(s, strlen(s), width, 0); +#else + return width; +#endif +} + /************************************************************** * Original: * Patrick Powell Tue Apr 11 09:48:21 PDT 1995