Debian Codegraph @

lib/mktime-internal.h

raw
1 /* Internals of mktime and related functions
2 Copyright 2016-2025 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Paul Eggert <[email protected]>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #ifndef _LIBC
21 # include <time.h>
22 # define __libc_lock_lock(lock) ((void) 0)
23 # define __libc_lock_unlock(lock) ((void) 0)
24 # define __tzset_unlocked() tzset ()
25 #endif
26
27 /* mktime_offset_t is a signed type wide enough to hold a UTC offset
28 in seconds, and used as part of the type of the offset-guess
29 argument to mktime_internal. In Glibc, it is always long int.
30 When in Gnulib, use time_t on platforms where time_t
31 is signed, to be compatible with platforms like BeOS that export
32 this implementation detail of mktime. On platforms where time_t is
33 unsigned, GNU and POSIX code can assume 'int' is at least 32 bits
34 which is wide enough for a UTC offset. */
35 #ifdef _LIBC
36 typedef long int mktime_offset_t;
37 #elif defined TIME_T_IS_SIGNED
38 typedef time_t mktime_offset_t;
39 #else
40 typedef int mktime_offset_t;
41 #endif
42
43 /* The source code uses identifiers like __time64_t for glibc
44 timestamps that can contain 64-bit values even when time_t is only
45 32 bits. These are just macros for the ordinary identifiers unless
46 compiling within glibc when time_t is 32 bits. */
47 #if ! (defined _LIBC && __TIMESIZE != 64)
48 # undef __time64_t
49 # define __time64_t time_t
50 # define __gmtime64_r __gmtime_r
51 # define __localtime64_r __localtime_r
52 # define __mktime64 mktime
53 # define __timegm64 timegm
54 #endif
55
56 #ifndef _LIBC
57
58 /* Although glibc source code uses leading underscores, Gnulib wants
59 ordinary names.
60
61 Portable standalone applications should supply a <time.h> that
62 declares a POSIX-compliant localtime_r, for the benefit of older
63 implementations that lack localtime_r or have a nonstandard one.
64 Similarly for gmtime_r. See the gnulib time_r module for one way
65 to implement this. */
66
67 # undef __gmtime_r
68 # undef __localtime_r
69 # define __gmtime_r gmtime_r
70 # define __localtime_r localtime_r
71
72 # define __mktime_internal mktime_internal
73
74 #endif
75
76 /* Subroutine of mktime. Return the time_t representation of TP and
77 normalize TP, given that a struct tm * maps to a time_t. If
78 LOCAL, the mapping is performed by localtime_r, otherwise by gmtime_r.
79 Record next guess for localtime-gmtime offset in *OFFSET.
80
81 If _LIBC, the caller must lock __tzset_lock. */
82 extern __time64_t __mktime_internal (struct tm *tp, bool local,
83 mktime_offset_t *offset) attribute_hidden;