MCPcopy Create free account
hub / github.com/coreutils/coreutils / set_LC_TIME

Function set_LC_TIME

src/date.c:342–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340 string or null. */
341
342static char *
343set_LC_TIME (char const *locale)
344{
345 /* It is not sufficient to do
346 setlocale (LC_TIME, locale);
347 because show_date relies on fprintftime, that uses the Gnulib module
348 'localename-unsafe', that looks at the values of the environment variables
349 (in order to distinguish the default locale from the C locale on platforms
350 like macOS). */
351 char const *all = getenv ("LC_ALL");
352 if (all != NULL && *all != '\0')
353 {
354 /* Setting LC_TIME when LC_ALL is set would have no effect. Therefore we
355 have to unset LC_ALL and sets its value to all locale categories that
356 are relevant for this program. */
357 xsetenv ("LC_CTYPE", all, 1); /* definitely needed */
358 xsetenv ("LC_TIME", all, 1); /* definitely needed */
359 xsetenv ("LC_MESSAGES", all, 1); /* definitely needed */
360 xsetenv ("LC_NUMERIC", all, 1); /* possibly needed */
361 /* xsetenv ("LC_COLLATE", all, 1); */ /* not needed */
362 /* xsetenv ("LC_MONETARY", all, 1); */ /* not needed */
363 unsetenv ("LC_ALL");
364 }
365
366 /* Set LC_TIME as an environment variable. */
367 char const *value = getenv ("LC_TIME");
368 char *ret = (value == NULL || *value == '\0' ? NULL : xstrdup (value));
369 if (locale != NULL)
370 xsetenv ("LC_TIME", locale, 1);
371 else
372 unsetenv ("LC_TIME");
373
374 /* Update the current locale accordingly. */
375 setlocale (LC_TIME, "");
376
377 return ret;
378}
379
380static bool
381show_date_helper (char const *format, bool use_c_locale,

Callers 1

show_date_helperFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected