[CRT]
[reactos.git] / lib / sdk / crt / time / futime.c
1 /*
2 * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
3 * PROJECT: ReactOS CRT library
4 * FILE: lib/sdk/crt/time/futime.c
5 * PURPOSE: Implementation of _futime
6 * PROGRAMERS: Timo Kreuzer
7 */
8 #include <precomp.h>
9 #define RC_INVOKED 1 // to prevent inline functions
10 #include <time.h>
11 #include <sys/utime.h>
12 #include "bitsfixup.h"
13
14 HANDLE fdtoh(int fd);
15
16 /******************************************************************************
17 * \name _futime
18 * \brief Set a files modification time.
19 * \param [out] ptimeb Pointer to a structure of type struct _timeb that
20 * recieves the current time.
21 * \sa http://msdn.microsoft.com/en-us/library/95e68951.aspx
22 */
23 int
24 _futime(int fd, struct _utimbuf *filetime)
25 {
26 HANDLE handle;
27 FILETIME at, wt;
28
29 handle = fdtoh(fd);
30 if (handle == INVALID_HANDLE_VALUE)
31 {
32 return -1;
33 }
34
35 if (!filetime)
36 {
37 time_t currTime;
38 _time(&currTime);
39 RtlSecondsSince1970ToTime(currTime, (LARGE_INTEGER *)&at);
40 wt = at;
41 }
42 else
43 {
44 RtlSecondsSince1970ToTime(filetime->actime, (LARGE_INTEGER *)&at);
45 if (filetime->actime == filetime->modtime)
46 {
47 wt = at;
48 }
49 else
50 {
51 RtlSecondsSince1970ToTime(filetime->modtime, (LARGE_INTEGER *)&wt);
52 }
53 }
54
55 if (!SetFileTime(handle, NULL, &at, &wt))
56 {
57 __set_errno(GetLastError());
58 return -1 ;
59 }
60
61 return 0;
62 }