1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-11-03 17:27:29 -05:00

Add the error-checking function xwcsdup()

This commit is contained in:
John Zaitseff 2011-08-20 10:40:07 +10:00
parent 02fd017807
commit 336611559b
6 changed files with 43 additions and 3 deletions

4
lib/.gitignore vendored
View File

@ -109,11 +109,15 @@ vfprintf.c
vsnprintf.c
wchar.in.h
wcrtomb.c
wcsdup-impl.h
wcsdup.c
wcsrtombs-impl.h
wcsrtombs-state.c
wcsrtombs.c
wctype.in.h
wcwidth.c
wmemcpy-impl.h
wmemcpy.c
xsize.h
alloca.h

2
m4/.gitignore vendored
View File

@ -110,8 +110,10 @@ warn-on-use.m4
wchar_h.m4
wchar_t.m4
wcrtomb.m4
wcsdup.m4
wcsrtombs.m4
wctype_h.m4
wcwidth.m4
wint_t.m4
wmemcpy.m4
xsize.m4

View File

@ -15,7 +15,7 @@
# Specification in the form of a command-line invocation:
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl assert btowc config-h ctype fprintf-posix getopt-gnu gettext gettext-h gettimeofday langinfo locale mbrtowc mbsrtowcs printf-posix sigaction signal snprintf-posix stat stdarg stdbool stdio strdup-posix striconv string strncat strstr sys_stat sys_time unistd vfprintf-posix vsnprintf-posix wchar wcrtomb wcsrtombs wctype-h wcwidth
# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl assert btowc config-h ctype fprintf-posix getopt-gnu gettext gettext-h gettimeofday langinfo locale mbrtowc mbsrtowcs printf-posix sigaction signal snprintf-posix stat stdarg stdbool stdio strdup-posix striconv string strncat strstr sys_stat sys_time unistd vfprintf-posix vsnprintf-posix wchar wcrtomb wcsdup wcsrtombs wctype-h wcwidth
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([])
@ -53,6 +53,7 @@ gl_MODULES([
vsnprintf-posix
wchar
wcrtomb
wcsdup
wcsrtombs
wctype-h
wcwidth

View File

@ -44,8 +44,6 @@ typedef struct txwin {
// Declarations for argument processing in mkchstr()
#define EILSEQ_REPL '?' // Illegal byte sequence replacement character
#define MAXFMTARGS 8 // Maximum number of positional arguments
enum argument_type {

View File

@ -487,5 +487,25 @@ char *xstrdup (const char *str)
}
/***********************************************************************/
// xwcsdup: Duplicate a wide-character string, with checking
wchar_t *xwcsdup (const wchar_t *str)
{
wchar_t *s;
if (str == NULL)
str = L"";
s = wcsdup(str);
if (s == NULL) {
err_exit_nomem();
}
return s;
}
/***********************************************************************/
// End of file

View File

@ -42,6 +42,9 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define EILSEQ_REPL '?' // Illegal character sequence replacement
/************************************************************************
* Global variable declarations *
************************************************************************/
@ -328,4 +331,16 @@ extern void *xmalloc (size_t size);
extern char *xstrdup (const char *str);
/*
Function: xwcsdup - Duplicate a wide-character string, with checking
Parameters: str - String to duplicate
Returns: wchar_t * - Pointer to new string, allocated with malloc()
This wrapper function duplicates a string by calling wcsdup(), then
checks if a NULL pointer has been returned. If so, the program
terminates with an "Out of memory" error.
*/
extern wchar_t *xwcsdup (const wchar_t *str);
#endif /* included_UTILS_H */