]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/timegm.3
membarrier.2: Remove redundant mention of return value of MEMBARRIER_CMD_SHARED
[thirdparty/man-pages.git] / man3 / timegm.3
CommitLineData
fea681da
MK
1.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da 24.\"
fe0fefbf 25.TH TIMEGM 3 2015-03-02 "GNU" "Linux Programmer's Manual"
fea681da 26.SH NAME
02011a43 27timegm, timelocal \- inverses of gmtime and localtime
fea681da
MK
28.SH SYNOPSIS
29.nf
30.B #include <time.h>
31.sp
b9f02710 32.BI "time_t timelocal(struct tm *" tm );
fea681da 33.sp
b9f02710 34.BI "time_t timegm(struct tm *" tm );
cc4615cc
MK
35.sp
36.fi
37.in -4n
38Feature Test Macro Requirements for glibc (see
39.BR feature_test_macros (7)):
40.in
41.sp
42.BR timelocal (),
43.BR timegm ():
44_BSD_SOURCE || _SVID_SOURCE
fea681da
MK
45.SH DESCRIPTION
46The functions
63aa9df0 47.BR timelocal ()
fea681da 48and
63aa9df0 49.BR timegm ()
02011a43 50are the inverses of
fea681da
MK
51.BR localtime (3)
52and
53.BR gmtime (3).
cd6fe8e7
PH
54.SH ATTRIBUTES
55For an explanation of the terms used in this section, see
56.BR attributes (7).
57.TS
58allbox;
59lbw21 lb lb
60l l l.
61Interface Attribute Value
62T{
63.BR timelocal (),
64.BR timegm ()
65T} Thread safety MT-Safe env locale
66.TE
47297adb 67.SH CONFORMING TO
c8f2dd47 68These functions are nonstandard GNU extensions
02011a43
MK
69that are also present on the BSDs.
70Avoid their use; see NOTES.
fea681da 71.SH NOTES
fea681da 72The
63aa9df0 73.BR timelocal ()
fea681da
MK
74function is equivalent to the POSIX standard function
75.BR mktime (3).
76There is no reason to ever use it.
77.LP
78For a portable version of
63aa9df0 79.BR timegm (),
fea681da
MK
80set the
81.B TZ
82environment variable to UTC, call
fb186734 83.BR mktime (3)
fea681da
MK
84and restore the value of
85.BR TZ .
86Something like
87
a6e2f128 88.in +4n
fea681da
MK
89.nf
90#include <time.h>
91#include <stdlib.h>
92
c13182ef
MK
93time_t
94my_timegm(struct tm *tm)
41798314 95{
fea681da
MK
96 time_t ret;
97 char *tz;
98
99 tz = getenv("TZ");
00a9a899
JG
100 if (tz)
101 tz = strdup(tz);
fea681da
MK
102 setenv("TZ", "", 1);
103 tzset();
104 ret = mktime(tm);
00a9a899 105 if (tz) {
fea681da 106 setenv("TZ", tz, 1);
00a9a899
JG
107 free(tz);
108 } else
fea681da
MK
109 unsetenv("TZ");
110 tzset();
111 return ret;
112}
113.fi
a6e2f128 114.in
47297adb 115.SH SEE ALSO
fea681da
MK
116.BR gmtime (3),
117.BR localtime (3),
118.BR mktime (3),
119.BR tzset (3)