logo

utils-std

Collection of commonly available Unix tools
commit: d644de1aaecfb86382eb23c91f71f314d0995c04
parent 294e468dd8fde2ac7bee6c7532142f56b8f7abae
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri,  5 Jul 2024 04:00:05 +0200

cmd/date: Handle setlocale error

Diffstat:

Mcmd/date.c7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/cmd/date.c b/cmd/date.c @@ -11,6 +11,7 @@ #include <locale.h> /* setlocale() */ #include <stdio.h> /* BUFSIZ, perror(), puts() */ #include <stdlib.h> /* exit(), strtol() */ +#include <string.h> /* strerror */ #include <time.h> /* time, localtime, tm, strftime, strptime */ #include <unistd.h> /* getopt(), optarg, optind */ @@ -33,7 +34,13 @@ main(int argc, char *argv[]) int dflag = 0; int c; + errno = 0; setlocale(LC_ALL, ""); + if(errno != 0) + { + fprintf(stderr, "date: Warning: Failed to initialize locales: %s\n", strerror(errno)); + errno = 0; + } now = time(NULL); if(now == (time_t)-1)