[openi18n-im:01341] strndup usage
Hidetoshi Tajima <[email protected]> Mon, 25 Apr 2005 15:43:06 -0700
| Newsgroups | gmane.comp.internationalization.input-methods |
|---|---|
| Message-ID | <[email protected]> |
strndup(3C) is GNUish, hence a patch like below will be needed for non GNU libc environments. Please review and approve commits into r12_2 and trunk. Regards, Toshi
patch_strndup
(text/plain, 1.5 KB)
Index: iiimsf/src/letools.cpp
===================================================================
--- iiimsf/src/letools.cpp (revision 2578)
+++ iiimsf/src/letools.cpp (working copy)
@@ -33,7 +33,7 @@
ACT_REMOVEMOD,
ACT_MODLIST,
ACT_APPENDKEY,
- ACT_REMOVEKEY,
+ ACT_REMOVEKEY
} ActionType;
struct _Action {
@@ -147,8 +147,34 @@
, name);
}
+#ifndef HAVE_STRNDUP
+static char *
+strndup(const char *s, size_t n)
+{
+ size_t slen;
+ char *dst;
+ size_t copied;
+
+ if (s == NULL || n == 0)
+ return NULL;
+
+ slen = strlen(s);
+ if (slen >= n)
+ copied = n;
+ else
+ copied = slen;
+
+ dst = (char*)malloc (copied + 1);
+ if (dst == NULL)
+ return NULL;
+
+ dst[copied] = '\0';
+ return (char *) memcpy (dst, s, copied);
+}
+#endif
+
static HotKeyStruct *
-parse_hotkey(const char *keys)
+parse_hotkey(char *keys)
{
HotKeyStruct *hstruct = NULL;
size_t len = strlen(keys);
Index: acfiles/check_sys.m4
===================================================================
--- acfiles/check_sys.m4 (revision 2578)
+++ acfiles/check_sys.m4 (working copy)
@@ -61,7 +61,7 @@
AC_CHECK_FUNCS(mkdir putenv uname endpwent)
AC_CHECK_FUNCS(memmove memset)
AC_CHECK_FUNCS(nl_langinfo setlocale)
- AC_CHECK_FUNCS(strdup strerror strstr strchr strrchr strspn strtol stpcpy)
+ AC_CHECK_FUNCS(strdup strndup strerror strstr strchr strrchr strspn strtol stpcpy)
AC_CHECK_FUNCS(bcopy bzero bcmp index rindex fork fork1 signal sigaction)
AC_CHECK_FUNCS(getpwuid getpwnam)
AC_CHECK_FUNCS(poll select bsearch)