[vlc-devel] [PATCH 3/3] posix: use strerror_r() if strerror_l() is unimplemented
Sean McGovern
gseanmcg at gmail.com
Sun Sep 13 03:30:35 CEST 2015
On Sat, Sep 12, 2015 at 2:03 PM, Rémi Denis-Courmont <remi at remlab.net>
wrote:
> Le 2015-09-12 20:23, Sean McGovern a écrit :
>
>> ---
>> src/posix/error.c | 26 ++++++++++++++++++++++++++
>> 1 file changed, 26 insertions(+)
>>
>> diff --git a/src/posix/error.c b/src/posix/error.c
>> index db51004..790e5bb 100644
>> --- a/src/posix/error.c
>> +++ b/src/posix/error.c
>> @@ -29,6 +29,23 @@
>>
>> #include <vlc_common.h>
>>
>> +#ifndef HAVE_STRERROR_L
>> +static const char *vlc_strerror_r(int errnum)
>> +{
>> +#define BUF_LEN 256
>> + char *buf = malloc(BUF_LEN);
>> + if(unlikely(buf == NULL))
>> + return buf;
>> +
>> + if(strerror_r(errnum, buf, BUF_LEN))
>> + {
>> + free(buf);
>> + buf = NULL;
>>
>
> This function is not allowed to return NULL. Call sites would crash.
>
>
Fair enough. I can have it return "Unknown error" or something similar.
> + }
>> +
>> + return buf;
>>
>
> Memory leak.
>
>
Doesn't the calling function need to take ownership of whatever this
returns anyhow?
> +}
>> +#else
>> static const char *vlc_strerror_l(int errnum, const char *lname)
>> {
>> int saved_errno = errno;
>> @@ -53,6 +70,7 @@ static const char *vlc_strerror_l(int errnum, const
>> char *lname)
>> freelocale(loc);
>> return buf;
>> }
>> +#endif
>>
>> /**
>> * Formats an error message in the current locale.
>> @@ -63,7 +81,11 @@ static const char *vlc_strerror_l(int errnum,
>> const char *lname)
>> const char *vlc_strerror(int errnum)
>> {
>> /* We cannot simply use strerror() here, since it is not
>> thread-safe. */
>> +#ifndef HAVE_STRERROR_L
>> + return vlc_strerror_r(errnum);
>> +#else
>> return vlc_strerror_l(errnum, "");
>> +#endif
>> }
>>
>> /**
>> @@ -74,5 +96,9 @@ const char *vlc_strerror(int errnum)
>> */
>> const char *vlc_strerror_c(int errnum)
>> {
>> +#ifndef HAVE_STRERROR_L
>> + return vlc_strerror_r(errnum);
>>
>
> This will cause translated error messages in the log. This might mean
> nothing to you. But *I* get to review a a lot of debug logs in locales I
> don't understand.
This doesn't mean nothing to me -- I'm just stuck with no clear idea on how
to move forward. I definitely don't have the resources to provide
translations for all the operating systems that have no implementation for
this.
-- Sean McG.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150912/d130d2e7/attachment.html>
More information about the vlc-devel
mailing list