summaryrefslogtreecommitdiffstats
path: root/private/crt32/time/ftime.c
blob: c1e04f5a1f5dc2b62b1627167d6ddaefa012f3d4 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***
*ftime.c - OS/2 return system time
*
*	Copyright (c) 1985-1993, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Returns the system date/time in a structure form.
*
*Revision History:
*	03-??-84  RLB	initial version
*	05-17-86  SKS	ported to OS/2
*	03-09-87  SKS	correct Daylight Savings Time flag
*	11-18-87  SKS	Change tzset() to __tzset()
*	12-11-87  JCR	Added "_LOAD_DS" to declaration
*	10-03-88  JCR	386: Change DOS calls to SYS calls
*	10-04-88  JCR	386: Removed 'far' keyword
*	10-10-88  GJF	Made API names match DOSCALLS.H
*	04-12-89  JCR	New syscall interface
*	05-25-89  JCR	386 OS/2 calls use '_syscall' calling convention
*	03-20-90  GJF	Replaced _LOAD_DS with _CALLTYPE1, added #include
*			<cruntime.h>, removed some leftover 16-bit support
*			and fixed the copyright. Also, cleaned up the
*			formatting a bit.
*	07-25-90  SBM	Removed '32' from API names
*	08-13-90  SBM	Compiles cleanly with -W3
*	08-20-90  SBM	Removed old incorrect, redundant tp->dstflag assignment
*	10-04-90  GJF	New-style function declarator.
*	12-04-90  SRW	Changed to include <oscalls.h> instead of <doscalls.h>
*	12-06-90  SRW	Added _CRUISER_ and _WIN32 conditionals.
*	01-21-91  GJF	ANSI naming.
*	01-23-92  GJF	Change in time zone field name for Win32, to support
*			crtdll.dll [_WIN32_].
*	03-30-93  GJF	Revised to use mktime(). Also purged Cruiser support.
*	06-08-93  SKS	Change "tmzone" back to "timezone".  See h/sys/timeb.h.
*	07-15-93  GJF	Call __tzset() instead of _tzset().
*
*******************************************************************************/

#ifndef _POSIX_

#include <cruntime.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
#include <dostypes.h>
#include <msdos.h>
#include <dos.h>
#include <stdlib.h>
#include <oscalls.h>
#include <internal.h>

/***
*void _ftime(timeptr) - return DOS time in a structure
*
*Purpose:
*	returns the current DOS time in a struct timeb structure
*
*Entry:
*	struct timeb *timeptr - structure to fill in with time
*
*Exit:
*	no return value -- fills in structure
*
*Exceptions:
*
*******************************************************************************/

void _CRTAPI1 _ftime (
	struct _timeb *tp
	)
{
	struct tm tb;
	SYSTEMTIME dt;

	__tzset();

	/*
	 * NOTE: The "timezone" field was renamed "tmzone" for a while because
	 * of the conflict with the global variable "_timezone".  Since we use
	 * #define to alias the old name "timezone" to "_timezone" and to
	 * alias _timezone to (*_timezone_dll) in the CRTDLL model, we cannot
	 * compatibility in both areas.  See sys/timeb.h for more information.
	 */
	tp->timezone = (short)(_timezone / 60);

	GetLocalTime(&dt);

	tp->millitm = (unsigned short)(dt.wMilliseconds);

	tb.tm_year  = dt.wYear - 1900;
	tb.tm_mday  = dt.wDay;
	tb.tm_mon   = dt.wMonth - 1;
	tb.tm_hour  = dt.wHour;
	tb.tm_min   = dt.wMinute;
	tb.tm_sec   = dt.wSecond;
	tb.tm_isdst = -1;

	/*
	 * Call mktime() to compute time_t value and Daylight Savings Time
	 * flag.
	 */
	tp->time = mktime(&tb);

	tp->dstflag = (short)(tb.tm_isdst);
}

#endif  /* _POSIX_ */