Commit d0822ab7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

posix: handle newlocale() errors

newlocale() will fail if the specified locale is not found. Here, it
can fail if the environment variables refer to an invalid or missing
locale.
Pointed-out-by: default avatarCasian Andrei <skeletk13@gmail.com>
parent 98362591
......@@ -23,13 +23,31 @@
#endif
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <assert.h>
#include <vlc_common.h>
static const char *vlc_strerror_l(int errnum, const char *lname)
{
int saved_errno = errno;
locale_t loc = newlocale(LC_MESSAGES_MASK, lname, (locale_t)0);
if (unlikely(loc == (locale_t)0))
{
if (errno == ENOENT) /* fallback to POSIX locale */
loc = newlocale(LC_MESSAGES_MASK, "C", (locale_t)0);
if (unlikely(loc == (locale_t)0))
{
assert(errno != EINVAL && errno != ENOENT);
errno = saved_errno;
return "Error message unavailable";
}
errno = saved_errno;
}
const char *buf = strerror_l(errnum, loc);
freelocale(loc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment