• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3914 (tree)
Time2018-11-24 14:13:11
Authormagicant

Log Message

Use wcsdup if available

The wcsdup function is mandatory in POSIX.1-2008 and many systems
support it. Let's take advantage of it.

Change Summary

Incremental Difference

--- yash/trunk/configure (revision 3913)
+++ yash/trunk/configure (revision 3914)
@@ -908,6 +908,29 @@
908908 defconfigh "HAVE_WCSNLEN"
909909 fi
910910
911+# check for wcsdup
912+checking 'for wcsdup'
913+cat >"${tempsrc}" <<END
914+${confighdefs}
915+#include <wchar.h>
916+#ifndef wcsdup
917+wchar_t *wcsdup(const wchar_t*);
918+#endif
919+int main(void) {
920+ char *dup = wcsdup("12345");
921+ if (!dup) return 1;
922+ int cmp = wcscmp(dup, "12345");
923+ free(dup);
924+ return cmp != 0;
925+}
926+END
927+trymake && tryexec
928+checked
929+if [ x"${checkresult}" = x"yes" ]
930+then
931+ defconfigh "HAVE_WCSDUP"
932+fi
933+
911934 # check for wcscasecmp
912935 checking 'for wcscasecmp'
913936 cat >"${tempsrc}" <<END
--- yash/trunk/util.h (revision 3913)
+++ yash/trunk/util.h (revision 3914)
@@ -165,16 +165,24 @@
165165
166166 /********** String Utilities **********/
167167
168+#if !HAVE_STRNLEN
168169 extern size_t xstrnlen(const char *s, size_t maxlen)
169170 __attribute__((pure,nonnull));
171+#endif
172+#if !HAVE_STRDUP
170173 extern char *xstrdup(const char *s)
171174 __attribute__((malloc,warn_unused_result,nonnull));
175+#endif
176+#if !HAVE_WCSNLEN
172177 extern size_t xwcsnlen(const wchar_t *s, size_t maxlen)
173178 __attribute__((pure,nonnull));
179+#endif
174180 extern wchar_t *xwcsndup(const wchar_t *s, size_t maxlen)
175181 __attribute__((malloc,warn_unused_result,nonnull));
182+#if !HAVE_WCSDUP
176183 static inline wchar_t *xwcsdup(const wchar_t *s)
177184 __attribute__((malloc,warn_unused_result,nonnull));
185+#endif
178186 extern _Bool xstrtoi(const char *s, int base, int *resultp)
179187 __attribute__((warn_unused_result,nonnull));
180188 extern _Bool xwcstoi(const wchar_t *s, int base, int *resultp)
@@ -211,6 +219,12 @@
211219 # define xwcsnlen wcsnlen
212220 #endif
213221
222+#if HAVE_WCSDUP
223+# ifndef wcsdup
224+extern wchar_t *wcsdup(const wchar_t *s);
225+# endif
226+# define xwcsdup wcsdup
227+#else
214228 /* Returns a newly malloced copy of the specified string.
215229 * Aborts the program if failed to allocate memory. */
216230 wchar_t *xwcsdup(const wchar_t *s)
@@ -217,6 +231,7 @@
217231 {
218232 return xwcsndup(s, Size_max);
219233 }
234+#endif
220235
221236
222237 /* These macros are used to cast the argument properly.
Show on old repository browser