Bug 14247 - newlocale doesn't always set errno upon failure return
: newlocale doesn't always set errno upon failure return
Status: NEW
Product: glibc
Classification: Unclassified
Component: localedata
: 2.15
: P2 normal
: ---
Assigned To: Not yet assigned to anyone
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-06-15 03:45 UTC by law
Modified: 2012-06-15 03:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Potential fix (708 bytes, application/octet-stream)
2012-06-15 03:45 UTC, law
Details

Note You need to log in before you can comment on or make changes to this bug.
Description law 2012-06-15 03:45:50 UTC
Created attachment 6449 [details]
Potential fix

newlocale() neglects to set errno to an appropriate value when failing, if it
has already been asked about the same incorrect locale name.

#include <stdio.h>
#include <errno.h>
#include <locale.h>

int
main(int argc, char **argv)
{
  locale_t loc;

  setlocale(LC_ALL, "C");

  errno = 0;
  loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK,
          "nb_no.utf8",
          0);
  printf("result = %p errno = %d\n", loc, errno);

  errno = 0;
  loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK,
          "nb_no.utf8",
          0);
  printf("result = %p errno = %d\n", loc, errno);

  return 0;
}


Actual results:
result = (nil) errno = 2
result = (nil) errno = 0

Expected results:
result = (nil) errno = 2
result = (nil) errno = 2     (or at least something other than 0)