From 463a8afaa58b80926b0236e14a6171f45c1b784f Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 23 Aug 2016 17:49:24 +0200 Subject: [PATCH] Implement missing POSIX-1.2008 function strerror_l Signed-off-by: Corinna Vinschen --- newlib/libc/string/strerror.c | 19 ++++++++++++++++++- winsup/cygwin/common.din | 1 + winsup/cygwin/errno.cc | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/newlib/libc/string/strerror.c b/newlib/libc/string/strerror.c index fcef33e0e..49e5f7e64 100644 --- a/newlib/libc/string/strerror.c +++ b/newlib/libc/string/strerror.c @@ -7,14 +7,18 @@ /* FUNCTION - <>---convert error number to string + <>, <>---convert error number to string INDEX strerror +INDEX + strerror_l + ANSI_SYNOPSIS #include char *strerror(int <[errnum]>); + char *strerror_l(int <[errnum]>, locale_t locale); char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>, int <[internal]>, int *<[error]>); @@ -29,6 +33,10 @@ string. The value of <[errnum]> is usually a copy of <>. If <> is not a known error number, the result points to an empty string. +<> is like <> but creates a string in a format +as expected in locale <[locale]>. If <[locale]> is LC_GLOBAL_LOCALE or +not a valid locale object, the behaviour is undefined. + This implementation of <> prints out the following strings for each of the values defined in `<>': @@ -330,6 +338,8 @@ PORTABILITY ANSI C requires <>, but does not specify the strings used for each error number. +<> is POSIX-1.2008. + Although this implementation of <> is reentrant (depending on <<_user_strerror>>), ANSI C declares that subsequent calls to <> may overwrite the result string; therefore portable @@ -893,3 +903,10 @@ _DEFUN(strerror, (int), { return _strerror_r (_REENT, errnum, 0, NULL); } + +char * +strerror_l (int errnum, locale_t locale) +{ + /* We don't support per-locale error messages. */ + return _strerror_r (_REENT, errnum, 0, NULL); +} diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din index 8f7a282f4..7fce58719 100644 --- a/winsup/cygwin/common.din +++ b/winsup/cygwin/common.din @@ -1345,6 +1345,7 @@ strcpy NOSIGFE strcspn NOSIGFE strdup SIGFE strerror SIGFE +strerror_l SIGFE strerror_r SIGFE strfmon SIGFE strfmon_l SIGFE diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index 7e07a6178..9168e9b4d 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -403,6 +403,13 @@ strerror (int errnum) return result; } +extern "C" char * +strerror_l (int errnum, locale_t locale) +{ + /* We don't provide localized system error messages (yet?). */ + return strerror (errnum); +} + /* Newlib's provides declarations for two strerror_r variants, according to preprocessor feature macros. However, it returns "" instead of "Unknown error ...", so we override both