summaryrefslogtreecommitdiffstats
path: root/private/crt32/time/systime.c
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/crt32/time/systime.c
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/crt32/time/systime.c')
-rw-r--r--private/crt32/time/systime.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/private/crt32/time/systime.c b/private/crt32/time/systime.c
new file mode 100644
index 000000000..cd7590cd0
--- /dev/null
+++ b/private/crt32/time/systime.c
@@ -0,0 +1,104 @@
+/***
+*systime.c - _getsystime and _setsystime
+*
+* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+* defines _getsystime() and _setsystime()
+*
+*Revision History:
+* 08-22-91 BWM Wrote module.
+* 05-19-92 DJM ifndef for POSIX build.
+* 09-25-92 SKS Use SetLocalTime(), not SetSystemTime().
+* Fix bug: daylight flag must be initialized to -1.
+* Replace C++ comments with C-style comments
+*
+*******************************************************************************/
+
+#ifndef _POSIX_
+
+#include <cruntime.h>
+#include <oscalls.h>
+#include <time.h>
+
+#if !defined(_WIN32_)
+#error ERROR - ONLY WIN32 TARGET SUPPORTED!
+#endif
+
+/***
+*unsigned _getsystime(timestruc, milliseconds) - Get current system time
+*
+*Purpose:
+*
+*Entry:
+ struct tm * ptm - time structure
+*
+*Exit:
+* milliseconds of current time
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+unsigned _CALLTYPE1 _getsystime(struct tm * ptm)
+{
+ SYSTEMTIME st;
+
+ GetLocalTime(&st);
+
+ ptm->tm_isdst = -1; /* mktime() computes whether this is */
+ /* during Standard or Daylight time. */
+ ptm->tm_sec = (int)st.wSecond;
+ ptm->tm_min = (int)st.wMinute;
+ ptm->tm_hour = (int)st.wHour;
+ ptm->tm_mday = (int)st.wDay;
+ ptm->tm_mon = (int)st.wMonth - 1;
+ ptm->tm_year = (int)st.wYear - 1900;
+ ptm->tm_wday = (int)st.wDayOfWeek;
+
+ /* Normalize uninitialized fields */
+ mktime(ptm);
+
+ return (st.wMilliseconds);
+}
+
+/***
+*unsigned _setsystime(timestruc, milliseconds) - Set new system time
+*
+*Purpose:
+*
+*Entry:
+* struct tm * ptm - time structure
+* unsigned milliseconds - milliseconds of current time
+*
+*Exit:
+* 0 if succeeds
+* system error if fails
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+unsigned _CALLTYPE1 _setsystime(struct tm * ptm, unsigned uMilliseconds)
+{
+ SYSTEMTIME st;
+
+ /* Normalize uninitialized fields */
+ mktime(ptm);
+
+ st.wYear = (WORD)(ptm->tm_year + 1900);
+ st.wMonth = (WORD)(ptm->tm_mon + 1);
+ st.wDay = (WORD)ptm->tm_mday;
+ st.wHour = (WORD)(ptm->tm_hour);
+ st.wMinute = (WORD)ptm->tm_min;
+ st.wSecond = (WORD)ptm->tm_sec;
+ st.wMilliseconds = (WORD)uMilliseconds;
+
+ if (!SetLocalTime(&st)) {
+ return ((int)GetLastError());
+ }
+
+ return (0);
+}
+
+#endif /* _POSIX_ */