[vlc-devel] [PATCH] Use strerror if strerror_l is unavailable.

Rémi Denis-Courmont remi at remlab.net
Sun Jul 10 16:06:04 CEST 2016


On perjantaina 8. heinäkuuta 2016 15.06.28 EEST Richard Diamond wrote:
> A few libc's (namely Newlib) don't provide strerror_l. On these platforms,
> this patch instead uses the locale indifferent strerror, using a global
> mutex and storing the requisite string buffer in a thread-local variable.
> Since a missing strerror_l probably implies that the libc in question
> doesn't implement any part of the locale API (ie only supports the 'C' or
> 'POSIX' locales), this patch just uses the default locale (ie 'C'/American
> English).

strerror() is not thread-safe, it cannot be used in a threaded program at all. 
Locking a mutex around it is naive; you need to use strerror_r().

(If you had a platform-specific manner to ascertain that strerror() is thread-
safe, then the mutex would not be necessary.)

Rémi Denis-Courmont

More information about the vlc-devel mailing list