#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#ifdef HANDLE_MULTIBYTE
+# include <mbswidth.h>
+#endif
#include "misc.h"
#ifdef ABOOK_SRC
# include "abook.h"
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);
#ifdef ABOOK_SRC
(char *) abook_realloc (buffer, size);
#else
- (char *) realloc (buffer, size);
+ (char *) xrealloc (buffer, size);
#endif
}
}
char*
strconcat (const char *str, ...)
{
- int l;
+ unsigned long l;
MY_VA_LOCAL_DECL;
char *s, *concat;
#ifdef ABOOK_SRC
abook_malloc(l);
#else
- malloc(l);
+ xmalloc(l);
#endif
+ if(concat == NULL)
+ return NULL;
strcpy (concat, str);
MY_VA_START(str);
my_getcwd()
{
char *dir = NULL;
- int size = 100;
+ size_t size = 100;
if( (dir = (char *)malloc(size)) == NULL)
return NULL;
+
+ *dir = 0;
while( getcwd(dir, size) == NULL && errno == ERANGE )
if( (dir = (char *)realloc(dir, size *=2)) == NULL)
#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 *
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