1 | /* $Id: RTTimeSet-os2.cpp 77120 2019-02-01 15:08:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTTimeSet, OS/2.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Contributed by knut st. osmundsen.
|
---|
8 | *
|
---|
9 | * Copyright (C) 2018 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * The contents of this file may alternatively be used under the terms
|
---|
20 | * of the Common Development and Distribution License Version 1.0
|
---|
21 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
22 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
23 | * CDDL are applicable instead of those of the GPL.
|
---|
24 | *
|
---|
25 | * You may elect to license modified versions of this file under the
|
---|
26 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
27 | *
|
---|
28 | * --------------------------------------------------------------------
|
---|
29 | *
|
---|
30 | * Copyright (c) 2018 knut st. osmundsen <[email protected]>
|
---|
31 | *
|
---|
32 | * Permission is hereby granted, free of charge, to any person
|
---|
33 | * obtaining a copy of this software and associated documentation
|
---|
34 | * files (the "Software"), to deal in the Software without
|
---|
35 | * restriction, including without limitation the rights to use,
|
---|
36 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
37 | * copies of the Software, and to permit persons to whom the
|
---|
38 | * Software is furnished to do so, subject to the following
|
---|
39 | * conditions:
|
---|
40 | *
|
---|
41 | * The above copyright notice and this permission notice shall be
|
---|
42 | * included in all copies or substantial portions of the Software.
|
---|
43 | *
|
---|
44 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
45 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
46 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
47 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
48 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
49 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
50 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
51 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
52 | */
|
---|
53 |
|
---|
54 |
|
---|
55 | /*********************************************************************************************************************************
|
---|
56 | * Header Files *
|
---|
57 | *********************************************************************************************************************************/
|
---|
58 | #define LOG_GROUP RTLOGGROUP_TIME
|
---|
59 | #define INCL_DOSDATETIME
|
---|
60 | #define INCL_DOSERRORS
|
---|
61 | #include <os2.h>
|
---|
62 |
|
---|
63 | #include <iprt/time.h>
|
---|
64 | #include "internal/iprt.h"
|
---|
65 |
|
---|
66 | #include <iprt/assert.h>
|
---|
67 | #include <iprt/errcore.h>
|
---|
68 |
|
---|
69 |
|
---|
70 | RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime)
|
---|
71 | {
|
---|
72 | /*
|
---|
73 | * Convert to local time and explode it, keeping the distance
|
---|
74 | * between UTC and local.
|
---|
75 | */
|
---|
76 | int64_t cNsLocalDelta = RTTimeLocalDeltaNanoFor(pTime);
|
---|
77 | RTTIMESPEC TimeLocal = *pTime;
|
---|
78 | RTTIME Exploded;
|
---|
79 | if (RTTimeExplode(&Exploded, RTTimeSpecAddNano(&TimeLocal, cNsLocalDelta)))
|
---|
80 | {
|
---|
81 | /*
|
---|
82 | * Fill in the OS/2 structure and make the call.
|
---|
83 | */
|
---|
84 | DATETIME DateTime;
|
---|
85 | DateTime.hours = Exploded.u8Hour;
|
---|
86 | DateTime.minutes = Exploded.u8Minute;
|
---|
87 | DateTime.seconds = Exploded.u8Second;
|
---|
88 | DateTime.hundredths = (uint8_t)(Exploded.u32Nanosecond / (RT_NS_1SEC_64 / 100));
|
---|
89 | DateTime.day = Exploded.u8MonthDay;
|
---|
90 | DateTime.month = Exploded.u8Month;
|
---|
91 | DateTime.year = (uint16_t)Exploded.i32Year;
|
---|
92 | DateTime.weekday = Exploded.u8WeekDay;
|
---|
93 |
|
---|
94 | /* Minutes from UTC. http://www.edm2.com/os2api/Dos/DosSetDateTime.html says
|
---|
95 | that timezones west of UTC should have a positive value. The kernel fails
|
---|
96 | the call if we're more than +/-780 min (13h) distant, so clamp it in
|
---|
97 | case of bogus TZ values. */
|
---|
98 | DateTime.timezone = (int16_t)(-cNsLocalDelta / (int64_t)RT_NS_1MIN);
|
---|
99 | if (DateTime.timezone > 780)
|
---|
100 | DateTime.timezone = 780;
|
---|
101 | else if (DateTime.timezone < -780)
|
---|
102 | DateTime.timezone = -780;
|
---|
103 |
|
---|
104 | APIRET rc = DosSetDateTime(&DateTime);
|
---|
105 | if (rc == NO_ERROR)
|
---|
106 | return VINF_SUCCESS;
|
---|
107 | AssertMsgFailed(("rc=%u\n", rc));
|
---|
108 | return RTErrConvertFromOS2(rc);
|
---|
109 | }
|
---|
110 | return VERR_INVALID_PARAMETER;
|
---|
111 | }
|
---|
112 |
|
---|