VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/os2/RTTimeSet-os2.cpp@ 75297

Last change on this file since 75297 was 75297, checked in by vboxsync, 7 years ago

IPRT: Better RTTimeSet for OS/2 by Y.T. Lets the time sync service keep the timezone info up to date.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: RTTimeSet-os2.cpp 75297 2018-11-07 00:28:36Z vboxsync $ */
2/** @file
3 * IPRT - RTTimeSet, OS/2.
4 */
5
6/*
7 * Copyright (c) 2018 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32/*********************************************************************************************************************************
33* Header Files *
34*********************************************************************************************************************************/
35#define LOG_GROUP RTLOGGROUP_TIME
36#define INCL_DOSDATETIME
37#include <os2.h>
38
39#include <iprt/time.h>
40#include "internal/iprt.h"
41
42#include <iprt/err.h>
43
44
45RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime)
46{
47 /*
48 * Convert to local time and explode it, keeping the distance
49 * between UTC and local.
50 */
51 int64_t cNsLocalDelta = RTTimeLocalDeltaNanoFor(pTime);
52 RTTIMESPEC TimeLocal = *pTime;
53 RTTIME Exploded;
54 if (RTTimeExplode(&Exploded, RTTimeSpecAddNano(&TimeLocal, cNsLocalDelta))))
55 {
56 /*
57 * Fill in the OS/2 structure and make the call.
58 */
59 DATETIME DateTime;
60 DateTime.hour = Exploded.u8Hour;
61 DateTime.minutes = Exploded.u8Minute;
62 DateTime.seconds = Exploded.u8Second;
63 DateTime.hundredths = (uint8_t)(Exploded.u32Nanosecond / (RT_NS_1SEC_64 / 100));
64 DateTime.day = Exploded.u8MonthDay;
65 DateTime.month = Exploded.u8Month;
66 DateTime.year = (uint16_t)Exploded.i32Year;
67 DateTime.weekday = Exploded.u8WeekDay;
68
69 /* Minutes from UTC. http://www.edm2.com/os2api/Dos/DosSetDateTime.html says
70 that timezones west of UTC should have a positive value. The kernel fails
71 the call if we're more than +/-780 min (13h) distant, so clamp it in
72 case of bogus TZ values. */
73 DateTime.timezone = (int16_t)(-cNsLocalDelta / RT_NS_1MIN);
74 if (DateTime.timezone > 780)
75 DateTime.timezone = 780;
76 else if (DateTime.timezone < -780)
77 DateTime.timezone = -780;
78
79 APIRET rc = DosSetDateTime(&DateTime);
80 if (rc == NO_ERROR)
81 return VINF_SUCCESS;
82 AssertRC(rc);
83 return RTErrConvertFromOS2(rc);
84 }
85 return VERR_INVALID_PARAMETER;
86}
87
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette