This is the mail archive of the libc-locales@sourceware.org mailing list for the GNU libc locales project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strftime_l and NULL


hi,

please note that the offence region is disabled with "#if 0" in the example.
(what means it is working fine). enable it again and the result should be
something like that:

 LANG=C ./a.out "%c"
Result string is "Sat May  1 10:45:25 2010"
Speicherzugriffsfehler


the example is based on the strftime man page.

hope that helps,
 wh

Petter Reinholdtsen schrieb:
> [Walter Harms]
>> In apples xlocale.h it is written: "If a NULL locale_t is passed, the C
>> locale will be used."
>>
>> With glibc2.10 i get a segfault, is this intentional ?
> 
> Please provide an example source file demonstrating the problem. :)
> 
> Happy hacking,
#define _GNU_SOURCE
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <xlocale.h>

int
main(int argc, char *argv[])
{
  char outstr[200];
  time_t t;
  struct tm *tmp;
  locale_t loc;

  t = time(NULL);
  tmp = localtime(&t);
  if (tmp == NULL) {
    perror("localtime");
    exit(EXIT_FAILURE);
  }

  (void)setlocale(LC_ALL, "C");

  if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
    fprintf(stderr, "strftime returned 0");
    exit(EXIT_FAILURE);
  }
  printf("Result string is \"%s\"\n", outstr);

  /*
    same as strftime()
  */

#if 0
  if (strftime_l(outstr, sizeof(outstr), argv[1], tmp,NULL) == 0) {
    fprintf(stderr, "strftime returned 0");
    exit(EXIT_FAILURE);
  }

  printf("Result string is \"%s\"\n", outstr);
#endif

  loc=newlocale(LC_ALL_MASK,"de_DE",NULL);

  if (strftime_l(outstr, sizeof(outstr), argv[1], tmp,loc) == 0) {
    fprintf(stderr, "strftime returned 0");
    exit(EXIT_FAILURE);
  }
  printf("Result string is \"%s\"\n", outstr);


  freelocale(loc);		

  exit(EXIT_SUCCESS);
} /* main */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]