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