ReactOS 0.4.16-dev-927-g467dec4
utime.cpp File Reference
Include dependency graph for utime.cpp:

Go to the source code of this file.

Functions

template<typename TimeType , typename Character , typename TimeBufferType >
static int __cdecl common_utime (Character const *const file_name, TimeBufferType *const times) throw ()
 
int __cdecl _utime32 (char const *const file_name, __utimbuf32 *const times)
 
int __cdecl _wutime32 (wchar_t const *const file_name, __utimbuf32 *const times)
 
int __cdecl _utime64 (char const *const file_name, __utimbuf64 *const times)
 
int __cdecl _wutime64 (wchar_t const *const file_name, __utimbuf64 *const times)
 
template<typename TimeType , typename TimeBufferType >
static int __cdecl common_futime (int const fh, TimeBufferType *times) throw ()
 
int __cdecl _futime32 (int const fh, __utimbuf32 *const times)
 
int __cdecl _futime64 (int const fh, __utimbuf64 *const times)
 

Function Documentation

◆ _futime32()

int __cdecl _futime32 ( int const  fh,
__utimbuf32 *const  times 
)

Definition at line 149 of file utime.cpp.

150{
151 return common_futime<__time32_t>(fh, times);
152}
static const struct encodedFiletime times[]
Definition: encode.c:556

◆ _futime64()

int __cdecl _futime64 ( int const  fh,
__utimbuf64 *const  times 
)

Definition at line 154 of file utime.cpp.

155{
156 return common_futime<__time64_t>(fh, times);
157}

◆ _utime32()

int __cdecl _utime32 ( char const *const  file_name,
__utimbuf32 *const  times 
)

Definition at line 49 of file utime.cpp.

50{
51 return common_utime<__time32_t>(file_name, times);
52}
static LPCWSTR file_name
Definition: protocol.c:147

◆ _utime64()

int __cdecl _utime64 ( char const *const  file_name,
__utimbuf64 *const  times 
)

Definition at line 59 of file utime.cpp.

60{
61 return common_utime<__time64_t>(file_name, times);
62}

◆ _wutime32()

int __cdecl _wutime32 ( wchar_t const *const  file_name,
__utimbuf32 *const  times 
)

Definition at line 54 of file utime.cpp.

55{
56 return common_utime<__time32_t>(file_name, times);
57}

◆ _wutime64()

int __cdecl _wutime64 ( wchar_t const *const  file_name,
__utimbuf64 *const  times 
)

Definition at line 64 of file utime.cpp.

65{
66 return common_utime<__time64_t>(file_name, times);
67}

◆ common_futime()

template<typename TimeType , typename TimeBufferType >
static int __cdecl common_futime ( int const  fh,
TimeBufferType *  times 
)
throw (
)
static

Definition at line 75 of file utime.cpp.

76{
77 typedef __crt_time_time_t_traits<TimeType> time_traits;
78
79 _CHECK_FH_RETURN(fh, EBADF, -1);
80
81 _VALIDATE_RETURN(fh >= 0 && static_cast<unsigned>(fh) < static_cast<unsigned>(_nhandle), EBADF, -1);
83
84 TimeBufferType default_times;
85
86 if (times == nullptr)
87 {
88 time_traits::time(&default_times.modtime);
89 default_times.actime = default_times.modtime;
90 times = &default_times;
91 }
92
93 tm tm_value;
94 if (time_traits::localtime_s(&tm_value, &times->modtime) != 0)
95 {
96 errno = EINVAL;
97 return -1;
98 }
99
101 local_time.wYear = static_cast<WORD>(tm_value.tm_year + 1900);
102 local_time.wMonth = static_cast<WORD>(tm_value.tm_mon + 1);
103 local_time.wDay = static_cast<WORD>(tm_value.tm_mday);
104 local_time.wHour = static_cast<WORD>(tm_value.tm_hour);
105 local_time.wMinute = static_cast<WORD>(tm_value.tm_min);
106 local_time.wSecond = static_cast<WORD>(tm_value.tm_sec);
107 local_time.wMilliseconds = 0;
108
109 SYSTEMTIME system_time;
110 FILETIME last_write_time;
111 if (!TzSpecificLocalTimeToSystemTime(nullptr, &local_time, &system_time) ||
112 !SystemTimeToFileTime(&system_time, &last_write_time))
113 {
114 errno = EINVAL;
115 return -1;
116 }
117
118 if (time_traits::localtime_s(&tm_value, &times->actime) != 0)
119 {
120 errno = EINVAL;
121 return -1;
122 }
123
124 local_time.wYear = static_cast<WORD>(tm_value.tm_year + 1900);
125 local_time.wMonth = static_cast<WORD>(tm_value.tm_mon + 1);
126 local_time.wDay = static_cast<WORD>(tm_value.tm_mday);
127 local_time.wHour = static_cast<WORD>(tm_value.tm_hour);
128 local_time.wMinute = static_cast<WORD>(tm_value.tm_min);
129 local_time.wSecond = static_cast<WORD>(tm_value.tm_sec);
130 local_time.wMilliseconds = 0;
131
132 FILETIME last_access_time;
133 if (!TzSpecificLocalTimeToSystemTime(nullptr, &local_time, &system_time) ||
134 !SystemTimeToFileTime(&system_time, &last_access_time))
135 {
136 errno = EINVAL;
137 return -1;
138 }
139
140 if (!SetFileTime(reinterpret_cast<HANDLE>(_get_osfhandle(fh)), nullptr, &last_access_time, &last_write_time))
141 {
142 errno = EINVAL;
143 return -1;
144 }
145
146 return 0;
147}
#define EINVAL
Definition: acclib.h:90
#define EBADF
Definition: acclib.h:82
#define _CHECK_FH_RETURN(handle, errorcode, retexpr)
int _nhandle
Definition: ioinit.cpp:34
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
static DOUBLE local_time(DOUBLE time, DateInstance *date)
Definition: date.c:351
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
BOOL WINAPI TzSpecificLocalTimeToSystemTime(LPTIME_ZONE_INFORMATION lpTimeZoneInformation, LPSYSTEMTIME lpLocalTime, LPSYSTEMTIME lpUniversalTime)
Definition: timezone.c:421
unsigned short WORD
Definition: ntddk_ex.h:93
#define FOPEN
#define errno
Definition: errno.h:18
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
#define _osfile(i)
Definition: internal.h:72
Definition: time.h:68
int tm_mon
Definition: time.h:73
int tm_year
Definition: time.h:74
int tm_hour
Definition: time.h:71
int tm_sec
Definition: time.h:69
int tm_mday
Definition: time.h:72
int tm_min
Definition: time.h:70

◆ common_utime()

template<typename TimeType , typename Character , typename TimeBufferType >
static int __cdecl common_utime ( Character const *const  file_name,
TimeBufferType *const  times 
)
throw (
)
static

Definition at line 17 of file utime.cpp.

21{
23
24 _VALIDATE_RETURN(file_name != nullptr, EINVAL, -1)
25
26 // Open the file, since the underlying system call needs a handle. Note
27 // that the _utime definition says you must have write permission for the
28 // file to change its time, so we open the file for write only. Also, we
29 // must force it to open in binary mode so that we don't remove ^Z's from
30 // binary files.
31 int fh;
32 if (time_traits::tsopen_s(&fh, file_name, _O_RDWR | _O_BINARY, _SH_DENYNO, 0) != 0)
33 return -1;
34
35 int const result = time_traits::futime(fh, times);
36
37 errno_t stored_errno = 0;
38 if (result == -1)
39 stored_errno = errno;
40
41 _close(fh);
42
43 if (result == -1)
44 errno = stored_errno;
45
47}
return
Definition: dirsup.c:529
#define _SH_DENYNO
Definition: share.h:17
#define _O_RDWR
Definition: cabinet.h:39
#define _O_BINARY
Definition: cabinet.h:51
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint64EXT * result
Definition: glext.h:11304
if(dx< 0)
Definition: linetemp.h:194
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
int errno_t
Definition: corecrt.h:615
#define const
Definition: zconf.h:233