VirtualBox

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

Last change on this file since 85561 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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

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