]> granicus.if.org Git - shadow/blob - libmisc/tz.c
* libmisc/chowntty.c: Improve the logs for fchown and fchmod
[shadow] / libmisc / tz.c
1 /*
2  * Copyright (c) 1991 - 1994, Julianne Frances Haugh
3  * Copyright (c) 1991 - 1994, Chip Rosenthal
4  * Copyright (c) 1996 - 1998, Marek Michałkiewicz
5  * Copyright (c) 2003 - 2005, Tomasz Kłoczko
6  * Copyright (c) 2007 - 2008, Nicolas François
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the copyright holders or contributors may not be used to
18  *    endorse or promote products derived from this software without
19  *    specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <config.h>
35
36 #ifndef USE_PAM
37
38 #ident "$Id$"
39
40 #include <stdio.h>
41 #include <string.h>
42 #include "defines.h"
43 #include "prototypes.h"
44 #include "getdef.h"
45
46 /*
47  * tz - return local timezone name
48  *
49  * tz() determines the name of the local timezone by reading the
50  * contents of the file named by ``fname''.
51  */
52 char *tz (const char *fname)
53 {
54         FILE *fp = 0;
55         static char tzbuf[BUFSIZ];
56         const char *def_tz = "TZ=CST6CDT";
57
58         if ((fp = fopen (fname, "r")) == NULL ||
59             fgets (tzbuf, (int) sizeof (tzbuf), fp) == NULL) {
60                 if (!(def_tz = getdef_str ("ENV_TZ")) || def_tz[0] == '/')
61                         def_tz = "TZ=CST6CDT";
62
63                 strcpy (tzbuf, def_tz);
64         } else
65                 tzbuf[strlen (tzbuf) - 1] = '\0';
66
67         if (fp)
68                 (void) fclose (fp);
69
70         return tzbuf;
71 }
72 #else                           /* !USE_PAM */
73 extern int errno;               /* warning: ANSI C forbids an empty source file */
74 #endif                          /* !USE_PAM */
75