:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / sys_stat / futime.c
1 #include <crtdll/alloc.h>
2 #include <crtdll/stdlib.h>
3 #include <crtdll/sys/utime.h>
4 #include <crtdll/io.h>
5 #include <crtdll/time.h>
6 #include <crtdll/errno.h>
7 #include <crtdll/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                 __set_errno(EBADF);
17                 return -1;
18         }  
19         
20         if ( pTimes == NULL ) {
21                 pTimes = alloca(sizeof(struct _utimbuf));
22                 time(&pTimes->actime);
23                 time(&pTimes->modtime);
24         }
25         
26         if ( pTimes->actime < pTimes->modtime  ) {
27                 __set_errno(EINVAL);
28                 return -1;
29         }
30                
31         UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0);
32         UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0);
33         if ( !SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime) ) {
34                 __set_errno(EBADF);
35                 return -1;
36         }
37
38         return 0;
39 }