Setlocale returns static buffer, don't assume it will be unchanged

Pointed by:	phantom
This commit is contained in:
Andrey A. Chernov 2002-03-10 14:54:59 +00:00
parent 8277f29174
commit dfe8796660
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=92006

View File

@ -42,7 +42,6 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <time.h>
#include "pathnames.h"
@ -140,7 +139,7 @@ void
settime(now)
time_t now;
{
char *oldl;
char *oldl, *lbufp;
tp = localtime(&now);
if ( isleap(tp->tm_year + 1900) ) {
@ -154,10 +153,15 @@ settime(now)
offset = tp->tm_wday == 5 ? 3 : 1;
header[5].iov_base = dayname;
oldl = setlocale(LC_TIME, NULL);
oldl = NULL;
lbufp = setlocale(LC_TIME, NULL);
if (lbufp != NULL && (oldl = strdup(lbufp)) == NULL)
errx(1, "cannot allocate memory");
(void) setlocale(LC_TIME, "C");
header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp);
(void) setlocale(LC_TIME, oldl);
(void) setlocale(LC_TIME, (oldl != NULL ? oldl : ""));
if (oldl != NULL)
free(oldl);
setnnames();
}