shadow/libmisc/tz.c
Alejandro Colomar bddcd9b095 Remove superfluous casts
-  Every non-const pointer converts automatically to void *.
-  Every pointer converts automatically to void *.
-  void * converts to any other pointer.
-  const void * converts to any other const pointer.
-  Integer variables convert to each other.

I changed the declaration of a few variables in order to allow removing
a cast.

However, I didn't attempt to edit casts inside comparisons, since they
are very delicate.  I also kept casts in variadic functions, since they
are necessary, and in allocation functions, because I have other plans
for them.

I also changed a few casts to int that are better as ptrdiff_t.

This change has triggered some warnings about const correctness issues,
which have also been fixed in this patch (see for example src/login.c).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-02-09 10:03:03 -06:00

59 lines
1.3 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 "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, 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 {
/* Remove optional trailing '\n'. */
tzbuf[strcspn (tzbuf, "\n")] = '\0';
}
if (NULL != fp) {
(void) fclose (fp);
}
return tzbuf;
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */