Use thread-safe functions newlocale(3), uselocale(3) and freelocale(3) over setlocale(3).

Try to use a thread-safe functions where available, or fallback to setlocale(3)
if such are not available. This is only to make it work with older versions
of the libmagic.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>