msvcrt: Add explicit 32- and 64-bit versions of the utime functions.

This commit is contained in:
Alexandre Julliard 2009-05-23 11:10:05 +02:00
parent 8408e3a955
commit 4a7b3460ef
5 changed files with 147 additions and 26 deletions

View File

@ -141,6 +141,16 @@ static void msvcrt_stat64_to_stati64(const struct MSVCRT__stat64 *buf64, struct
buf->st_ctime = buf64->st_ctime;
}
static void time_to_filetime( MSVCRT___time64_t time, FILETIME *ft )
{
/* 1601 to 1970 is 369 years plus 89 leap days */
static const __int64 secs_1601_to_1970 = ((369 * 365 + 89) * (__int64)86400);
__int64 ticks = (time + secs_1601_to_1970) * 10000000;
ft->dwHighDateTime = ticks >> 32;
ft->dwLowDateTime = ticks;
}
static inline BOOL msvcrt_is_valid_fd(int fd)
{
return fd >= 0 && fd < MSVCRT_fdend && (MSVCRT_fdesc[fd].wxflag & WX_OPEN);
@ -1213,27 +1223,22 @@ int CDECL MSVCRT__fstat(int fd, struct MSVCRT__stat* buf)
}
/*********************************************************************
* _futime (MSVCRT.@)
* _futime64 (MSVCRT.@)
*/
int CDECL _futime(int fd, struct MSVCRT__utimbuf *t)
int CDECL _futime64(int fd, struct MSVCRT___utimbuf64 *t)
{
HANDLE hand = msvcrt_fdtoh(fd);
FILETIME at, wt;
if (!t)
{
MSVCRT_time_t currTime;
MSVCRT_time(&currTime);
RtlSecondsSince1970ToTime(currTime, (LARGE_INTEGER *)&at);
wt = at;
time_to_filetime( MSVCRT__time64(NULL), &at );
wt = at;
}
else
{
RtlSecondsSince1970ToTime(t->actime, (LARGE_INTEGER *)&at);
if (t->actime == t->modtime)
wt = at;
else
RtlSecondsSince1970ToTime(t->modtime, (LARGE_INTEGER *)&wt);
time_to_filetime( t->actime, &at );
time_to_filetime( t->modtime, &wt );
}
if (!SetFileTime(hand, NULL, &at, &wt))
@ -1244,6 +1249,32 @@ int CDECL _futime(int fd, struct MSVCRT__utimbuf *t)
return 0;
}
/*********************************************************************
* _futime32 (MSVCRT.@)
*/
int CDECL _futime32(int fd, struct MSVCRT___utimbuf32 *t)
{
struct MSVCRT___utimbuf64 t64;
t64.actime = t->actime;
t64.modtime = t->modtime;
return _futime64( fd, &t64 );
}
/*********************************************************************
* _futime (MSVCRT.@)
*/
#ifdef _WIN64
int CDECL _futime(int fd, struct MSVCRT___utimbuf64 *t)
{
return _futime64( fd, t );
}
#else
int CDECL _futime(int fd, struct MSVCRT___utimbuf32 *t)
{
return _futime32( fd, t );
}
#endif
/*********************************************************************
* _get_osfhandle (MSVCRT.@)
*/
@ -2053,15 +2084,15 @@ int CDECL MSVCRT__umask(int umask)
}
/*********************************************************************
* _utime (MSVCRT.@)
* _utime64 (MSVCRT.@)
*/
int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t)
int CDECL _utime64(const char* path, struct MSVCRT___utimbuf64 *t)
{
int fd = MSVCRT__open(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY);
if (fd > 0)
{
int retVal = _futime(fd, t);
int retVal = _futime64(fd, t);
MSVCRT__close(fd);
return retVal;
}
@ -2069,21 +2100,73 @@ int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t)
}
/*********************************************************************
* _wutime (MSVCRT.@)
* _utime32 (MSVCRT.@)
*/
int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT__utimbuf *t)
int CDECL _utime32(const char* path, struct MSVCRT___utimbuf32 *t)
{
struct MSVCRT___utimbuf64 t64;
t64.actime = t->actime;
t64.modtime = t->modtime;
return _utime64( path, &t64 );
}
/*********************************************************************
* _utime (MSVCRT.@)
*/
#ifdef _WIN64
int CDECL _utime(const char* path, struct MSVCRT___utimbuf64 *t)
{
return _utime64( path, t );
}
#else
int CDECL _utime(const char* path, struct MSVCRT___utimbuf32 *t)
{
return _utime32( path, t );
}
#endif
/*********************************************************************
* _wutime64 (MSVCRT.@)
*/
int CDECL _wutime64(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf64 *t)
{
int fd = _wopen(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY);
if (fd > 0)
{
int retVal = _futime(fd, t);
int retVal = _futime64(fd, t);
MSVCRT__close(fd);
return retVal;
}
return -1;
}
/*********************************************************************
* _wutime32 (MSVCRT.@)
*/
int CDECL _wutime32(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf32 *t)
{
struct MSVCRT___utimbuf64 t64;
t64.actime = t->actime;
t64.modtime = t->modtime;
return _wutime64( path, &t64 );
}
/*********************************************************************
* _wutime (MSVCRT.@)
*/
#ifdef _WIN64
int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf64 *t)
{
return _wutime64( path, t );
}
#else
int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf32 *t)
{
return _wutime32( path, t );
}
#endif
/*********************************************************************
* _write (MSVCRT.@)
*/

View File

@ -335,10 +335,16 @@ struct MSVCRT__wfinddatai64_t {
MSVCRT_wchar_t name[260];
};
struct MSVCRT__utimbuf
struct MSVCRT___utimbuf32
{
MSVCRT_time_t actime;
MSVCRT_time_t modtime;
MSVCRT___time32_t actime;
MSVCRT___time32_t modtime;
};
struct MSVCRT___utimbuf64
{
MSVCRT___time64_t actime;
MSVCRT___time64_t modtime;
};
/* for FreeBSD */

View File

@ -272,6 +272,8 @@
@ cdecl -ret64 _ftol() ntdll._ftol
@ cdecl _fullpath(ptr str long)
@ cdecl _futime(long ptr)
@ cdecl _futime32(long ptr)
@ cdecl _futime64(long ptr)
@ cdecl _gcvt(double long str)
@ cdecl _get_osfhandle(long)
@ cdecl _get_sbh_threshold()
@ -521,6 +523,8 @@
@ cdecl _unlink(str) MSVCRT__unlink
@ cdecl _unloaddll(long)
@ cdecl _unlock(long)
@ cdecl _utime32(str ptr)
@ cdecl _utime64(str ptr)
@ cdecl _utime(str ptr)
@ cdecl _vscprintf(str ptr)
@ cdecl _vscwprintf(wstr ptr)
@ -608,6 +612,8 @@
@ cdecl _wtol(wstr) ntdll._wtol
@ cdecl _wunlink(wstr)
@ cdecl _wutime(wstr ptr)
@ cdecl _wutime32(wstr ptr)
@ cdecl _wutime64(wstr ptr)
@ cdecl _y0(double)
@ cdecl _y1(double)
@ cdecl _yn(long double )

View File

@ -219,9 +219,12 @@ static void test_structs(void)
CHECK_FIELD(_wfinddatai64_t, time_write);
CHECK_FIELD(_wfinddatai64_t, size);
CHECK_FIELD(_wfinddatai64_t, name[260]);
CHECK_STRUCT(_utimbuf);
CHECK_FIELD(_utimbuf, actime);
CHECK_FIELD(_utimbuf, modtime);
CHECK_STRUCT(__utimbuf32);
CHECK_FIELD(__utimbuf32, actime);
CHECK_FIELD(__utimbuf32, modtime);
CHECK_STRUCT(__utimbuf64);
CHECK_FIELD(__utimbuf64, actime);
CHECK_FIELD(__utimbuf64, modtime);
CHECK_STRUCT(_stat);
CHECK_FIELD(_stat, st_dev);
CHECK_FIELD(_stat, st_ino);

View File

@ -31,15 +31,38 @@ struct _utimbuf
time_t actime;
time_t modtime;
};
struct __utimbuf32
{
__time32_t actime;
__time32_t modtime;
};
struct __utimbuf64
{
__time64_t actime;
__time64_t modtime;
};
#endif /* _UTIMBUF_DEFINED */
#ifdef __cplusplus
extern "C" {
#endif
int __cdecl _futime(int,struct _utimbuf*);
int __cdecl _utime(const char*,struct _utimbuf*);
int __cdecl _wutime(const wchar_t*,struct _utimbuf*);
int __cdecl _futime32(int,struct __utimbuf32*);
int __cdecl _futime64(int,struct __utimbuf64*);
int __cdecl _utime32(const char*,struct __utimbuf32*);
int __cdecl _utime64(const char*,struct __utimbuf64*);
int __cdecl _wutime32(const wchar_t*,struct __utimbuf32*);
int __cdecl _wutime64(const wchar_t*,struct __utimbuf64*);
#ifdef _USE_32BIT_TIME_T
static inline int _futime(int fd, struct _utimbuf *buf) { return _futime32(fd, (struct __utimbuf32*)buf); }
static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime32(s, (struct __utimbuf32*)buf); }
static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime32(s, (struct __utimbuf32*)buf); }
#else
static inline int _futime(int fd, struct _utimbuf *buf) { return _futime64(fd, (struct __utimbuf64*)buf); }
static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime64(s, (struct __utimbuf64*)buf); }
static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime64(s, (struct __utimbuf64*)buf); }
#endif
#ifdef __cplusplus
}