Use ErrnoMaintainer in setlocale() to protect errno.

* this avoids spurious errno changes leaking into application code,
  which could become confused - i.e. 'rm' on a gcc4 build would always
  prompt for confirmation

I spend a couple of hours hunting down the behavioural difference
between gcc2- and gcc4-builds and it turns out that the reason for that
is that gcc4's libstdc++-code initializes its own locale data via the
POSIX calls, which trigger (correct) errno value changes, which were the
ones leaking into application code.
This commit is contained in:
Oliver Tappe 2011-11-24 23:47:27 +01:00
parent 59e43b2ac9
commit 8fd51c0819

View File

@ -10,6 +10,8 @@
#include <stdlib.h>
#include <string.h>
#include <ErrnoMaintainer.h>
#include "LocaleBackend.h"
@ -67,6 +69,8 @@ GetLocalesFromEnvironment(int category, const char** locales)
extern "C" char*
setlocale(int category, const char* locale)
{
BPrivate::ErrnoMaintainer errnoMaintainer;
if (category < 0 || category > LC_LAST)
return NULL;