From 19da58be2d9359a9641381feb559be0b918ef710 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 22:46:53 +0200 Subject: Adding upstream version 1:4.13+dfsg1. Signed-off-by: Daniel Baumann --- libmisc/tz.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 libmisc/tz.c (limited to 'libmisc/tz.c') diff --git a/libmisc/tz.c b/libmisc/tz.c new file mode 100644 index 0000000..16d92ad --- /dev/null +++ b/libmisc/tz.c @@ -0,0 +1,57 @@ +/* + * SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1991 - 1994, Chip Rosenthal + * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko + * SPDX-FileCopyrightText: 2007 - 2010, Nicolas François + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#ifndef USE_PAM + +#ident "$Id$" + +#include +#include +#include "defines.h" +#include "prototypes.h" +#include "getdef.h" + +/* + * tz - return local timezone name + * + * tz() determines the name of the local timezone by reading the + * contents of the file named by ``fname''. + */ +/*@observer@*/const char *tz (const char *fname) +{ + FILE *fp = NULL; + static char tzbuf[BUFSIZ]; + const char *def_tz = "TZ=CST6CDT"; + + fp = fopen (fname, "r"); + if ( (NULL == fp) + || (fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL)) { + def_tz = getdef_str ("ENV_TZ"); + if ((NULL == def_tz) || ('/' == def_tz[0])) { + def_tz = "TZ=CST6CDT"; + } + + strcpy (tzbuf, def_tz); + } else { + tzbuf[strlen (tzbuf) - 1] = '\0'; + } + + if (NULL != fp) { + (void) fclose (fp); + } + + return tzbuf; +} +#else /* !USE_PAM */ +extern int errno; /* warning: ANSI C forbids an empty source file */ +#endif /* !USE_PAM */ + -- cgit v1.2.3