Download raw body.
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]
Hi Sven,
Thank you for alleviating my frustration. :-)
On Fri, Aug 02, 2024 at 12:21:43PM +0200, Sven M. Hallberg wrote:
> NB: Calling date() twice in puthead() seems wrong and is useless anyway,
> since it never returns NULL.
Right, thanks!
I thought to use strftime_l() like you suggest, but as far as I tested
it, the only way that strftime is affected by the system locale (I mean
in other systems than OpenBSD) is setting the locale in the code. While
you don't do that, strftime() is not affected by the system locale.
I don't know if in other systems it could be affected anyways.
I wrote the little test program below to facilitate the test. Under
Linux, first generate some alternate locale, for example ja.JA.UTF-8.
Then run:
$ export LC_TIME=ja.JA.UTF-8
$ cc date.c
$ ./a.out
Then comment out the following line from date() function:
//setlocale(LC_TIME, "");
And run again:
$ cc date.c
$ ./a.out
The second time the program should print the date in Japanese.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
char *date(void);
int
main()
{
printf("Out of strftime:\t%s\n", date());
return 0;
}
char*
date(void)
{
struct tm newtime;
time_t ltime;
static char buf[32];
/* RUN THE TEST AGAIN COMMENTING OUT THIS LINE */
//setlocale(LC_TIME, "");
ltime = time(<ime);
localtime_r(<ime, &newtime);
strftime (buf, sizeof(buf), "%a, %d %b %Y %T %z", &newtime);
return (buf);
}
--
Walter
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]