VirtualBox

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

Last change on this file since 76553 was 76452, checked in by vboxsync, 5 years ago

IPRT: Ran scm --fix-err-h. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: RTTimeSet-os2.cpp 76452 2018-12-25 01:41:25Z 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#define INCL_DOSERRORS
38#include <os2.h>
39
40#include <iprt/time.h>
41#include "internal/iprt.h"
42
43#include <iprt/assert.h>
44#include <iprt/errcore.h>
45
46
47RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime)
48{
49 /*
50 * Convert to local time and explode it, keeping the distance
51 * between UTC and local.
52 */
53 int64_t cNsLocalDelta = RTTimeLocalDeltaNanoFor(pTime);
54 RTTIMESPEC TimeLocal = *pTime;
55 RTTIME Exploded;
56 if (RTTimeExplode(&Exploded, RTTimeSpecAddNano(&TimeLocal, cNsLocalDelta)))
57 {
58 /*
59 * Fill in the OS/2 structure and make the call.
60 */
61 DATETIME DateTime;
62 DateTime.hours = Exploded.u8Hour;
63 DateTime.minutes = Exploded.u8Minute;
64 DateTime.seconds = Exploded.u8Second;
65 DateTime.hundredths = (uint8_t)(Exploded.u32Nanosecond / (RT_NS_1SEC_64 / 100));
66 DateTime.day = Exploded.u8MonthDay;
67 DateTime.month = Exploded.u8Month;
68 DateTime.year = (uint16_t)Exploded.i32Year;
69 DateTime.weekday = Exploded.u8WeekDay;
70
71 /* Minutes from UTC. http://www.edm2.com/os2api/Dos/DosSetDateTime.html says
72 that timezones west of UTC should have a positive value. The kernel fails
73 the call if we're more than +/-780 min (13h) distant, so clamp it in
74 case of bogus TZ values. */
75 DateTime.timezone = (int16_t)(-cNsLocalDelta / (int64_t)RT_NS_1MIN);
76 if (DateTime.timezone > 780)
77 DateTime.timezone = 780;
78 else if (DateTime.timezone < -780)
79 DateTime.timezone = -780;
80
81 APIRET rc = DosSetDateTime(&DateTime);
82 if (rc == NO_ERROR)
83 return VINF_SUCCESS;
84 AssertMsgFailed(("rc=%u\n", rc));
85 return RTErrConvertFromOS2(rc);
86 }
87 return VERR_INVALID_PARAMETER;
88}
89
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use