ReactOS  0.4.15-dev-1070-ge1a01de
futime.c
Go to the documentation of this file.
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: Wine team
7  */
8 
9 /*
10  * msvcrt.dll file functions
11  *
12  * Copyright 1996,1998 Marcus Meissner
13  * Copyright 1996 Jukka Iivonen
14  * Copyright 1997,2000 Uwe Bonnes
15  * Copyright 2000 Jon Griffiths
16  * Copyright 2004 Eric Pouech
17  * Copyright 2004 Juan Lang
18  *
19  * This library is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU Lesser General Public
21  * License as published by the Free Software Foundation; either
22  * version 2.1 of the License, or (at your option) any later version.
23  *
24  * This library is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  * Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public
30  * License along with this library; if not, write to the Free Software
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32  *
33  * TODO
34  * Use the file flag hints O_SEQUENTIAL, O_RANDOM, O_SHORT_LIVED
35  */
36 
37 #include <precomp.h>
38 #define RC_INVOKED 1 // to prevent inline functions
39 #include <time.h>
40 #include <sys/utime.h>
41 #include "bitsfixup.h"
42 #include <internal/wine/msvcrt.h>
43 
44 ioinfo* get_ioinfo(int fd);
46 
47 /******************************************************************************
48  * \name _futime
49  * \brief Set a file's modification time.
50  * \param [out] ptimeb Pointer to a structure of type struct _timeb that
51  * receives the current time.
52  * \sa http://msdn.microsoft.com/en-us/library/95e68951.aspx
53  */
54 int
55 _futime(int fd, struct _utimbuf *filetime)
56 {
58  FILETIME at, wt;
59 
60  if (info->handle == INVALID_HANDLE_VALUE)
61  {
63  return -1;
64  }
65 
66  if (!filetime)
67  {
68  time_t currTime;
69  _time(&currTime);
71  (LARGE_INTEGER *)&at);
72  wt = at;
73  }
74  else
75  {
77  (LARGE_INTEGER *)&at);
78  if (filetime->actime == filetime->modtime)
79  {
80  wt = at;
81  }
82  else
83  {
85  (LARGE_INTEGER *)&wt);
86  }
87  }
88 
89  if (!SetFileTime(info->handle, NULL, &at, &wt))
90  {
93  return -1 ;
94  }
96  return 0;
97 }
Definition: file.c:40
Definition: utime.h:24
NTSYSAPI VOID NTAPI RtlSecondsSince1970ToTime(_In_ ULONG SecondsSince1970, _Out_ PLARGE_INTEGER Time)
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
time_t _time(time_t *ptime)
Definition: time.c:12
static int fd
Definition: io.c:51
int _futime(int fd, struct _utimbuf *filetime)
Definition: futime.c:55
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
void release_ioinfo(ioinfo *info)
Definition: file.c:263
smooth NULL
Definition: ftsmooth.c:416
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
__kernel_time_t time_t
Definition: linux.h:252
unsigned int ULONG
Definition: retypes.h:1