2 * reactos time user/kernel memory handling functions emulation of libcaptive
3 * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "captive/rtl-time.h" /* self */
23 #include <glib/gmessages.h>
24 #include "reactos/ntos/rtl.h" /* For RtlSecondsSince1970ToTime() */
27 /* It MUST match those of: reactos/ntoskrnl/rtl/time.c */
28 #define TICKSPERSEC 10000000
29 #define TICKSTO1970 0x019db1ded53e8000LL
33 * @Time: Target %PLARGE_INTEGER type target MS-Windows timestamp.
34 * %NULL value is forbidden.
35 * @timespec: Source %struct %timespec type UNIX timestamp.
36 * %NULL value is forbidden.
38 * Converts the timestamp format including the sub-second part not handled by
39 * just ReactOS RtlSecondsSince1970ToTime().
41 * Returns: %GNOME_VFS_OK if everything got converted OK.
43 GnomeVFSResult timespec_to_Time(PLARGE_INTEGER Time,const struct timespec *timespec)
45 g_return_val_if_fail(Time!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
46 g_return_val_if_fail(timespec!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
47 g_return_val_if_fail(timespec->tv_nsec<0,GNOME_VFS_ERROR_BAD_PARAMETERS);
48 g_return_val_if_fail(timespec->tv_nsec>1000000000,GNOME_VFS_ERROR_BAD_PARAMETERS);
50 RtlSecondsSince1970ToTime(timespec->tv_sec,Time);
52 /* #define TICKSPERSEC 10000000 */
53 #if TICKSPERSEC<1000000000 && !(1000000000%TICKSPERSEC)
54 Time->QuadPart+=timespec->tv_nsec / (1000000000/TICKSPERSEC);
56 #error "Unsupported: TICKSPERSEC"
63 * @timespec: Target %struct %timespec type UNIX timestamp.
64 * %NULL value is forbidden.
65 * @Time: Source %PLARGE_INTEGER type target MS-Windows timestamp.
66 * %NULL value is forbidden.
68 * Converts the timestamp format including the sub-second part not handled by
69 * just ReactOS RtlTimeToSecondsSince1970().
71 * Returns: %GNOME_VFS_OK if everything got converted OK.
73 GnomeVFSResult Time_to_timespec(struct timespec *timespec,const PLARGE_INTEGER Time)
75 ULONG SecondsSince1970;
78 g_return_val_if_fail(timespec!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
79 g_return_val_if_fail(Time!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
81 errBOOLEAN=RtlTimeToSecondsSince1970(Time,&SecondsSince1970);
82 g_assert(errBOOLEAN==TRUE);
84 timespec->tv_sec=SecondsSince1970;
86 /* #define TICKSPERSEC 10000000 */
88 /* Some problem with the remainer? */
89 #if TICKSTO1970%TICKSPERSEC
90 #error "Unsupported: TICKSTO1970
93 #if TICKSPERSEC<1000000000 && !(1000000000%TICKSPERSEC)
94 timespec->tv_nsec=(Time->QuadPart%TICKSPERSEC) * (1000000000/TICKSPERSEC);
96 #error "Unsupported: TICKSPERSEC"