update for HEAD-2003021201
[reactos.git] / lib / crtdll / sys_stat / futime.c
1 #include <msvcrt/alloc.h>
2 #include <msvcrt/stdlib.h>
3 #include <msvcrt/sys/utime.h>
4 #include <msvcrt/io.h>
5 #include <msvcrt/time.h>
6 #include <msvcrt/errno.h>
7 #include <msvcrt/internal/file.h>
8
9
10 int _futime(int nHandle, struct _utimbuf* pTimes)
11 {
12     FILETIME LastAccessTime;
13     FILETIME LastWriteTime;
14
15     // check for stdin / stdout  handles ??
16     if (nHandle == -1) {
17         __set_errno(EBADF);
18         return -1;
19     }
20
21     if (pTimes == NULL) {
22         pTimes = alloca(sizeof(struct _utimbuf));
23         time(&pTimes->actime);
24         time(&pTimes->modtime);
25     }
26
27     if (pTimes->actime < pTimes->modtime) {
28         __set_errno(EINVAL);
29         return -1;
30     }
31
32     UnixTimeToFileTime(pTimes->actime, &LastAccessTime, 0);
33     UnixTimeToFileTime(pTimes->modtime, &LastWriteTime, 0);
34     if (!SetFileTime(_get_osfhandle(nHandle), NULL, &LastAccessTime, &LastWriteTime)) {
35         __set_errno(EBADF);
36         return -1;
37     }
38
39     return 0;
40 }