Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gettimeo.c « go32 « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f4f7c874d639b32ebd4365bbde5fe7ee3480ced (plain)
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
51
52
53
54
55
56
57
58
59
60
61
/*
  (c) Copyright 1992 Eric Backus

  This software may be used freely so long as this copyright notice is
  left intact.  There is no warrantee on this software.
*/

#include <time.h>
#include <sys/time.h>
#include "dos.h"

static int daylight, gmtoffset;

int
gettimeofday (struct timeval *tp, struct timezone *tzp)
{

  if (tp)
  {
    struct time t;
    struct date d;
    struct tm tmrec;

    gettime (&t);
    getdate (&d);
    tmrec.tm_year = d.da_year - 1900;
    tmrec.tm_mon = d.da_mon - 1;
    tmrec.tm_mday = d.da_day;
    tmrec.tm_hour = t.ti_hour;
    tmrec.tm_min = t.ti_min;
    tmrec.tm_sec = t.ti_sec;
/*    tmrec.tm_gmtoff = gmtoffset;*/
    tmrec.tm_isdst = daylight;
    tp->tv_sec = mktime (&tmrec);
    tp->tv_usec = t.ti_hund * (1000000 / 100);
  }
  if (tzp)
  {
    tzp->tz_minuteswest = gmtoffset;
    tzp->tz_dsttime = daylight;
  }

  return 0;
}

void
__gettimeofday_init ()
{
  time_t ltm, gtm;
  struct tm *lstm;

  daylight = 0;
  gmtoffset = 0;
  ltm = gtm = time (NULL);
  ltm = mktime (lstm = localtime (&ltm));
  gtm = mktime (gmtime (&gtm));
  daylight = lstm->tm_isdst;
  gmtoffset = (int)(gtm - ltm) / 60;

}