- Reimplement time functions using ntdll functions.

- Some cleanups.
This commit is contained in:
György 'Nog' Jeney 2002-12-13 20:30:06 +00:00 committed by Alexandre Julliard
parent b3123fac25
commit f7694794de
5 changed files with 94 additions and 204 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Win32 kernel functions * Win32 kernel time functions
* *
* Copyright 1995 Martin von Loewis and Cameron Heide * Copyright 1995 Martin von Loewis and Cameron Heide
* *
@ -59,47 +59,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(win32);
BOOL WINAPI SetLocalTime( BOOL WINAPI SetLocalTime(
const SYSTEMTIME *systime) /* [in] The desired local time. */ const SYSTEMTIME *systime) /* [in] The desired local time. */
{ {
struct timeval tv; FILETIME ft;
struct tm t; LARGE_INTEGER st;
time_t sec; NTSTATUS status;
time_t oldsec=time(NULL);
int err;
/* get the number of seconds */ SystemTimeToFileTime( systime, &ft );
t.tm_sec = systime->wSecond;
t.tm_min = systime->wMinute;
t.tm_hour = systime->wHour;
t.tm_mday = systime->wDay;
t.tm_mon = systime->wMonth - 1;
t.tm_year = systime->wYear - 1900;
t.tm_isdst = -1;
sec = mktime (&t);
/* set the new time */ RtlLocalTimeToSystemTime( (PLARGE_INTEGER)&ft, &st );
tv.tv_sec = sec;
tv.tv_usec = systime->wMilliseconds * 1000;
/* error and sanity check*/ if ((status = NtSetSystemTime(&st, NULL)))
if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ SetLastError( RtlNtStatusToDosError(status) );
err = 1; return !status;
SetLastError(ERROR_INVALID_PARAMETER);
} else {
#ifdef HAVE_SETTIMEOFDAY
err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
if(err == 0)
return TRUE;
SetLastError(ERROR_PRIVILEGE_NOT_HELD);
#else
err = 1;
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
#endif
}
ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
systime->wYear, systime->wMonth, systime->wDay, systime->wHour,
systime->wMinute, systime->wSecond,
sec-oldsec, err == -1 ? "No Permission" :
sec==(time_t)-1 ? "" : "is too large." );
return FALSE;
} }
@ -142,19 +112,10 @@ BOOL WINAPI GetSystemTimeAdjustment(
BOOL WINAPI SetSystemTime( BOOL WINAPI SetSystemTime(
const SYSTEMTIME *systime) /* [in] The desired system time. */ const SYSTEMTIME *systime) /* [in] The desired system time. */
{ {
TIME_FIELDS tf;
LARGE_INTEGER t; LARGE_INTEGER t;
NTSTATUS status; NTSTATUS status;
tf.Second = systime->wSecond; SystemTimeToFileTime( systime, (PFILETIME)&t );
tf.Minute = systime->wMinute;
tf.Hour = systime->wHour;
tf.Day = systime->wDay;
tf.Month = systime->wMonth;
tf.Year = systime->wYear;
tf.Milliseconds = systime->wMilliseconds;
RtlTimeFieldsToTime(&tf, &t);
if ((status = NtSetSystemTime(&t, NULL))) if ((status = NtSetSystemTime(&t, NULL)))
SetLastError( RtlNtStatusToDosError(status) ); SetLastError( RtlNtStatusToDosError(status) );
@ -496,3 +457,87 @@ BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft,
SetLastError( RtlNtStatusToDosError(status) ); SetLastError( RtlNtStatusToDosError(status) );
return !status; return !status;
} }
/*********************************************************************
* FileTimeToSystemTime (KERNEL32.@)
*/
BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
{
TIME_FIELDS tf;
RtlTimeToTimeFields((PLARGE_INTEGER)ft, &tf);
syst->wYear = tf.Year;
syst->wMonth = tf.Month;
syst->wDay = tf.Day;
syst->wHour = tf.Hour;
syst->wMinute = tf.Minute;
syst->wSecond = tf.Second;
syst->wMilliseconds = tf.Milliseconds;
syst->wDayOfWeek = tf.Weekday;
return TRUE;
}
/*********************************************************************
* SystemTimeToFileTime (KERNEL32.@)
*/
BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
{
TIME_FIELDS tf;
tf.Year = syst->wYear;
tf.Month = syst->wMonth;
tf.Day = syst->wDay;
tf.Hour = syst->wHour;
tf.Minute = syst->wMinute;
tf.Second = syst->wSecond;
tf.Milliseconds = syst->wMilliseconds;
RtlTimeFieldsToTime(&tf, (PLARGE_INTEGER)ft);
return TRUE;
}
/*********************************************************************
* CompareFileTime (KERNEL32.@)
*/
INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
{
if (!x || !y) return -1;
if (x->dwHighDateTime > y->dwHighDateTime)
return 1;
if (x->dwHighDateTime < y->dwHighDateTime)
return -1;
if (x->dwLowDateTime > y->dwLowDateTime)
return 1;
if (x->dwLowDateTime < y->dwLowDateTime)
return -1;
return 0;
}
/*********************************************************************
* GetLocalTime (KERNEL32.@)
*/
VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
{
FILETIME lft;
LARGE_INTEGER ft;
NtQuerySystemTime(&ft);
RtlSystemTimeToLocalTime(&ft, (PLARGE_INTEGER)&lft);
FileTimeToSystemTime(&lft, systime);
}
/*********************************************************************
* GetSystemTime (KERNEL32.@)
*/
VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
{
FILETIME ft;
NtQuerySystemTime((PLARGE_INTEGER)&ft);
FileTimeToSystemTime(&ft, systime);
}

View file

@ -72,7 +72,6 @@ C_SRCS = \
$(TOPOBJDIR)/win32/except.c \ $(TOPOBJDIR)/win32/except.c \
$(TOPOBJDIR)/win32/kernel32.c \ $(TOPOBJDIR)/win32/kernel32.c \
$(TOPOBJDIR)/win32/newfns.c \ $(TOPOBJDIR)/win32/newfns.c \
$(TOPOBJDIR)/win32/time.c \
cdrom.c \ cdrom.c \
critsection.c \ critsection.c \
debugtools.c \ debugtools.c \

View file

@ -2481,25 +2481,6 @@ BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
return TRUE; return TRUE;
} }
/***********************************************************************
* FileTimeToSystemTime (KERNEL32.@)
*/
BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
{
struct tm *xtm;
DWORD remainder;
time_t xtime = DOSFS_FileTimeToUnixTime( ft, &remainder );
xtm = gmtime(&xtime);
syst->wYear = xtm->tm_year+1900;
syst->wMonth = xtm->tm_mon + 1;
syst->wDayOfWeek = xtm->tm_wday;
syst->wDay = xtm->tm_mday;
syst->wHour = xtm->tm_hour;
syst->wMinute = xtm->tm_min;
syst->wSecond = xtm->tm_sec;
syst->wMilliseconds = remainder / 10000;
return TRUE;
}
/*********************************************************************** /***********************************************************************
* QueryDosDeviceA (KERNEL32.@) * QueryDosDeviceA (KERNEL32.@)
@ -2561,41 +2542,6 @@ DWORD WINAPI QueryDosDeviceW(LPCWSTR devname,LPWSTR target,DWORD bufsize)
} }
/***********************************************************************
* SystemTimeToFileTime (KERNEL32.@)
*/
BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
{
#ifdef HAVE_TIMEGM
struct tm xtm;
time_t utctime;
#else
struct tm xtm,*utc_tm;
time_t localtim,utctime;
#endif
xtm.tm_year = syst->wYear-1900;
xtm.tm_mon = syst->wMonth - 1;
xtm.tm_wday = syst->wDayOfWeek;
xtm.tm_mday = syst->wDay;
xtm.tm_hour = syst->wHour;
xtm.tm_min = syst->wMinute;
xtm.tm_sec = syst->wSecond; /* this is UTC */
xtm.tm_isdst = -1;
#ifdef HAVE_TIMEGM
utctime = timegm(&xtm);
DOSFS_UnixTimeToFileTime( utctime, ft,
syst->wMilliseconds * 10000 );
#else
localtim = mktime(&xtm); /* now we've got local time */
utc_tm = gmtime(&localtim);
utctime = mktime(utc_tm);
DOSFS_UnixTimeToFileTime( 2*localtim -utctime, ft,
syst->wMilliseconds * 10000 );
#endif
return TRUE;
}
/*********************************************************************** /***********************************************************************
* DefineDosDeviceA (KERNEL32.@) * DefineDosDeviceA (KERNEL32.@)
*/ */

View file

@ -1037,24 +1037,6 @@ BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime,
return TRUE; return TRUE;
} }
/***********************************************************************
* CompareFileTime (KERNEL32.@)
*/
INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
{
if (!x || !y) return -1;
if (x->dwHighDateTime > y->dwHighDateTime)
return 1;
if (x->dwHighDateTime < y->dwHighDateTime)
return -1;
if (x->dwLowDateTime > y->dwLowDateTime)
return 1;
if (x->dwLowDateTime < y->dwLowDateTime)
return -1;
return 0;
}
/*********************************************************************** /***********************************************************************
* FILE_GetTempFileName : utility for GetTempFileName * FILE_GetTempFileName : utility for GetTempFileName
*/ */

View file

@ -1,82 +0,0 @@
/*
* Win32 kernel functions
*
* Copyright 1995 Martin von Loewis and Cameron Heide
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <string.h>
#include <time.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "file.h"
#include "winerror.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(win32);
/***********************************************************************
* GetLocalTime (KERNEL32.@)
*/
VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
{
time_t local_time;
struct tm *local_tm;
struct timeval tv;
gettimeofday(&tv, NULL);
local_time = tv.tv_sec;
local_tm = localtime(&local_time);
systime->wYear = local_tm->tm_year + 1900;
systime->wMonth = local_tm->tm_mon + 1;
systime->wDayOfWeek = local_tm->tm_wday;
systime->wDay = local_tm->tm_mday;
systime->wHour = local_tm->tm_hour;
systime->wMinute = local_tm->tm_min;
systime->wSecond = local_tm->tm_sec;
systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
}
/***********************************************************************
* GetSystemTime (KERNEL32.@)
*/
VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
{
time_t system_time;
struct tm *system_tm;
struct timeval tv;
gettimeofday(&tv, NULL);
system_time = tv.tv_sec;
system_tm = gmtime(&system_time);
systime->wYear = system_tm->tm_year + 1900;
systime->wMonth = system_tm->tm_mon + 1;
systime->wDayOfWeek = system_tm->tm_wday;
systime->wDay = system_tm->tm_mday;
systime->wHour = system_tm->tm_hour;
systime->wMinute = system_tm->tm_min;
systime->wSecond = system_tm->tm_sec;
systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
}