]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Time/timegm.c
StdLib: Add isDirSep character classification macro and function. Implement several...
[mirror_edk2.git] / StdLib / LibC / Time / timegm.c
CommitLineData
d7ce7006 1/** @file \r
2 timegm implementation\r
3\r
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are licensed and made available under\r
6 the terms and conditions of the BSD License that accompanies this distribution.\r
7 The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 * Copyright (c) 1987, 1989 Regents of the University of California.\r
14 * All rights reserved.\r
15 *\r
16 * This code is derived from software contributed to Berkeley by\r
17 * Arthur David Olson of the National Cancer Institute.\r
18 *\r
19 * Redistribution and use in source and binary forms, with or without\r
20 * modification, are permitted provided that the following conditions\r
21 * are met:\r
22 * 1. Redistributions of source code must retain the above copyright\r
23 * notice, this list of conditions and the following disclaimer.\r
24 * 2. Redistributions in binary form must reproduce the above copyright\r
25 * notice, this list of conditions and the following disclaimer in the\r
26 * documentation and/or other materials provided with the distribution.\r
27 * 3. All advertising materials mentioning features or use of this software\r
28 * must display the following acknowledgement:\r
29 * This product includes software developed by the University of\r
30 * California, Berkeley and its contributors.\r
31 * 4. Neither the name of the University nor the names of its contributors\r
32 * may be used to endorse or promote products derived from this software\r
33 * without specific prior written permission.\r
34 *\r
35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
45 * SUCH DAMAGE.\r
46\r
47static char *sccsid = "from: @(#)ctime.c 5.26 (Berkeley) 2/23/91";\r
48\r
49\r
50 * This implementation of mktime is lifted straight from the NetBSD (BSD 4.4)\r
51 * version. I modified it slightly to divorce it from the internals of the\r
52 * ctime library. Thus this version can't use details of the internal\r
53 * timezone state file to figure out strange unnormalized struct tm values,\r
54 * as might result from someone doing date math on the tm struct then passing\r
55 * it to mktime.\r
56 *\r
57 * It just does as well as it can at normalizing the tm input, then does a\r
58 * binary search of the time space using the system's localtime() function.\r
59 *\r
60 * The original binary search was defective in that it didn't consider the\r
61 * setting of tm_isdst when comparing tm values, causing the search to be\r
62 * flubbed for times near the dst/standard time changeover. The original\r
63 * code seems to make up for this by grubbing through the timezone info\r
64 * whenever the binary search barfed. Since I don't have that luxury in\r
65 * portable code, I have to take care of tm_isdst in the comparison routine.\r
66 * This requires knowing how many minutes offset dst is from standard time.\r
67 *\r
68 * So, if you live somewhere in the world where dst is not 60 minutes offset,\r
69 * and your vendor doesn't supply mktime(), you'll have to edit this variable\r
70 * by hand. Sorry about that.\r
71\r
72 $NetBSD: mktime.c,v 1.4 2006/06/11 19:34:10 kardel Exp $\r
73**/\r
74\r
75#include <LibConfig.h>\r
76#include <time.h>\r
77\r
78/*\r
79 This funciton is in Time.c, which has a different license than timegm.\r
80*/\r
81time_t \r
82time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),\r
83 const long offset, int * const okayp);\r
84\r
85/*\r
86 This funciton is in Time.c, which has a different license than timegm.\r
87*/\r
88void\r
89gmtsub(\r
90 const time_t * const timep,\r
91 const long offset,\r
92 struct tm * const tmp\r
93 );\r
94\r
95#ifndef WRONG\r
96#define WRONG (-1)\r
97#endif /* !defined WRONG */\r
98\r
99/*\r
100 Convert a tm structure to a GMT based time_t.\r
101*/\r
102time_t timegm( struct tm * tmp )\r
103{\r
104 register time_t t;\r
105 int okay;\r
106\r
107 tmp->tm_isdst = 0;\r
108 t = time2(tmp, gmtsub, 0, &okay);\r
109 if (okay || tmp->tm_isdst < 0)\r
110 return t;\r
111\r
112 return WRONG;\r
113}