This is the mail archive of the
libc-locales@sourceware.org
mailing list for the GNU libc locales project.
Re: strftime_l and NULL
- From: walter harms <wharms at bfs dot de>
- To: Petter Reinholdtsen <pere at hungry dot com>
- Cc: libc-locales at sources dot redhat dot com
- Date: Sat, 01 May 2010 10:55:14 +0200
- Subject: Re: strftime_l and NULL
- References: <4BDAF086.9030008@bfs.de> <20100430180151.GB12919@login2.uio.no>
- Reply-to: wharms at bfs dot de
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 */