xref: /titanic_41/usr/src/lib/libast/common/tm/tmzone.c (revision 5203bc321053fb87d7073c7640548fab73634793)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * time conversion support
28  */
29 
30 #include <ast.h>
31 #include <tm.h>
32 
33 /*
34  * return timezone pointer given name and type
35  *
36  * if type==0 then all time zone types match
37  * otherwise type must be one of tm_info.zone[].type
38  *
39  * if end is non-null then it will point to the next
40  * unmatched char in name
41  *
42  * if dst!=0 then it will point to 0 for standard zones
43  * and the offset for daylight zones
44  *
45  * 0 returned for no match
46  */
47 
48 Tm_zone_t*
49 tmzone(register const char* name, char** end, const char* type, int* dst)
50 {
51 	register Tm_zone_t*	zp;
52 	register char*		prev;
53 	char*			e;
54 
55 	static Tm_zone_t	fixed;
56 	static char		off[16];
57 
58 	tmset(tm_info.zone);
59 	if ((*name == '+' || *name == '-') && (fixed.west = tmgoff(name, &e, TM_LOCALZONE)) != TM_LOCALZONE && !*e)
60 	{
61 		fixed.standard = fixed.daylight = strncpy(off, name, sizeof(off) - 1);
62 		if (end)
63 			*end = e;
64 		if (dst)
65 			*dst = 0;
66 		return &fixed;
67 	}
68 	zp = tm_info.local;
69 	prev = 0;
70 	do
71 	{
72 		if (zp->type)
73 			prev = zp->type;
74 		if (!type || type == prev || !prev)
75 		{
76 			if (tmword(name, end, zp->standard, NiL, 0))
77 			{
78 				if (dst)
79 					*dst = 0;
80 				return zp;
81 			}
82 			if (zp->dst && zp->daylight && tmword(name, end, zp->daylight, NiL, 0))
83 			{
84 				if (dst)
85 					*dst = zp->dst;
86 				return zp;
87 			}
88 		}
89 		if (zp == tm_info.local)
90 			zp = tm_data.zone;
91 		else
92 			zp++;
93 	} while (zp->standard);
94 	return 0;
95 }
96