File: timegm.c

package info (click to toggle)
jabberd2 2.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 4,016 kB
  • sloc: ansic: 37,099; sh: 1,108; perl: 656; xml: 561; makefile: 511; python: 238; ruby: 145; sql: 55
file content (50 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifndef HAVE_TIMEGM
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

#if !defined(HAVE_SNPRINTF) || defined(HAVE_BROKEN_SNPRINTF)
int ap_snprintf(char *, size_t, const char *, ...);
# define snprintf ap_snprintf
#endif

/* jabberd2 Windows DLL */
#ifndef JABBERD2_API
# ifdef _WIN32
#  ifdef JABBERD2_EXPORTS
#   define JABBERD2_API  __declspec(dllexport)
#  else /* JABBERD2_EXPORTS */
#   define JABBERD2_API  __declspec(dllimport)
#  endif /* JABBERD2_EXPORTS */
# else /* _WIN32 */
#  define JABBERD2_API extern
# endif /* _WIN32 */
#endif /* JABBERD2_API */

JABBERD2_API time_t timegm(struct tm *tm)
{
    time_t ret;
    char *tz;
    
    /* save current timezone and set UTC */
    tz = getenv("TZ");
    putenv("TZ=UTC");   /* use Coordinated Universal Time (i.e. zero offset) */
    tzset();
    
    ret = mktime(tm);
    if(tz)
    {
        char buf[256];
        snprintf(buf, sizeof(buf), "TZ=%s", tz);
        putenv(buf);
    } else
        putenv("TZ=");
    tzset();
    
    return ret;
}
#endif