Files
shadow/lib/tz.c
Tobias Stoeckmann e6a5484ced lib: Eliminate dead code
The tz function is only called if ENV_TZ starts with a slash.

If the specified file cannot be read, the code implies that ENV_TZ
would be returned if it does not start with a slash.

Since we know that it DOES start with a slash, the code can be
simplified to state that "TZ=CST6CDT" is returned as a default if
the specified file cannot be read.

Benefit of this change is that strcpy's use case here can be
easier verified.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-29 12:23:05 +02:00

57 lines
1.1 KiB
C

/*
* 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 <config.h>
#ifndef USE_PAM
#ident "$Id$"
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
#include "string/strtok/stpsep.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;
const char *result;
static char tzbuf[BUFSIZ];
fp = fopen (fname, "r");
if ( (NULL == fp)
|| (fgets (tzbuf, sizeof (tzbuf), fp) == NULL)) {
result = "TZ=CST6CDT";
} else {
stpsep(tzbuf, "\n");
result = tzbuf;
}
if (NULL != fp) {
(void) fclose (fp);
}
return result;
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */