summaryrefslogtreecommitdiffstats
path: root/private/crt32/time/strtime.c
blob: 7525b672d85697733df9ed061d539fc83b59eaf3 (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
/***
*strtime.c - contains the function "_strtime()" for OS/2
*
*	Copyright (c) 1989-1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	contains the function _strtime()
*
*Revision History:
*	06-07-89  PHG	Module created, based on asm version
*	03-20-90  GJF	Made calling type _CALLTYPE1, added #include
*			<cruntime.h> and fixed the copyright. Also, cleaned
*			up the formatting a bit.
*	07-25-90  SBM	Removed '32' from API names
*	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.
*	05-19-92  DJM	ifndef for POSIX build.
*
*******************************************************************************/

#ifndef _POSIX_

#include <cruntime.h>
#include <time.h>
#include <oscalls.h>

/***
*char *_strtime(buffer) - return time in string form
*
*Purpose:
*	_strtime() returns a string containing the time in "HH:MM:SS" form
*
*Entry:
*	char *buffer = the address of a 9-byte user buffer
*
*Exit:
*	returns buffer, which contains the time in "HH:MM:SS" form
*
*Exceptions:
*
*******************************************************************************/

char * _CALLTYPE1 _strtime (
	char *buffer
	)
{
        int hours, minutes, seconds;

#ifdef	_CRUISER_
	DATETIME os2time;                       /* OS/2 time structure */

	/* ask OS/2 for the time, no error possible */
	DOSGETDATETIME(&os2time);
	hours = os2time.hours;
	minutes = os2time.minutes;
	seconds = os2time.seconds;

#else	/* ndef _CRUISER_ */

#ifdef	_WIN32_
        SYSTEMTIME dt;                       /* Win32 time structure */

        GetLocalTime(&dt);
	hours = dt.wHour;
	minutes = dt.wMinute;
	seconds = dt.wSecond;

#else	/* ndef _WIN32_ */

#error ERROR - ONLY CRUISER OR WIN32 TARGET SUPPORTED!

#endif	/* _WIN32_ */

#endif	/* _CRUISER_ */

	/* store the components of the time into the string */
	/* store separators */
	buffer[2] = buffer[5] = ':';
	/* store end of string */
	buffer[8] = '\0';
	/* store tens of hour */
	buffer[0] = (char) (hours   / 10 + '0');
	/* store units of hour */
	buffer[1] = (char) (hours   % 10 + '0');
	/* store tens of minute */
	buffer[3] = (char) (minutes / 10 + '0');
	/* store units of minute */
	buffer[4] = (char) (minutes % 10 + '0');
	/* store tens of second */
	buffer[6] = (char) (seconds / 10 + '0');
	/* store units of second */
	buffer[7] = (char) (seconds % 10 + '0');

	return buffer;
}

#endif  /* _POSIX_ */