update for HEAD-2003091401
[reactos.git] / lib / msvcrt / 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 /*
11  * @implemented
12  */
13 int _futime (int nHandle, struct _utimbuf *pTimes)
14 {
15   FILETIME  LastAccessTime;
16   FILETIME  LastWriteTime;
17
18   // check for stdin / stdout  handles ??
19   if (nHandle == -1) {
20       __set_errno(EBADF);
21       return -1;
22   }
23
24   if (pTimes == NULL) {
25       pTimes = alloca(sizeof(struct _utimbuf));
26       time(&pTimes->actime);
27       time(&pTimes->modtime);
28   }
29
30   if (pTimes->actime < pTimes->modtime) {
31       __set_errno(EINVAL);
32       return -1;
33   }
34
35   UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0);
36   UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0);
37   if (!SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime)) {
38       __set_errno(EBADF);
39       return -1;
40   }
41
42   return 0;
43 }