[Bug localedata/14247] New: newlocale doesn't always set errno upon failure return

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Bug localedata/14247] New: newlocale doesn't always set errno upon failure return

glaubitz at physik dot fu-berlin.de
http://sourceware.org/bugzilla/show_bug.cgi?id=14247

             Bug #: 14247
           Summary: newlocale doesn't always set errno upon failure return
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: localedata
        AssignedTo: [hidden email]
        ReportedBy: [hidden email]
                CC: [hidden email]
    Classification: Unclassified


Created attachment 6449
  --> http://sourceware.org/bugzilla/attachment.cgi?id=6449
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)

--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.