Removed double NAME entry.
[AROS.git] / compiler / clib / utimes.c
blob10ff5d36216182f862da125e0f7a0d3fc322ef3f
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <proto/dos.h>
9 #include <errno.h>
11 #include "__upath.h"
13 /*****************************************************************************
15 NAME */
16 #include <sys/time.h>
18 int utimes(
19 /* SYNOPSIS */
21 const char *file,
22 const struct timeval tvp[2])
24 /* FUNCTION
25 Change last access and last modification time of the given file to
26 times specified in tvp array. If tvp is NULL, the current time will be
27 used instead.
29 INPUTS
30 filename - Name of the file
31 buf - Pointer to an array of two timeval structures. First structure
32 specifies the last access time, second specifies the last
33 modification time
35 RESULT
36 0 on success and -1 on error. If an error occurred, the global
37 variable errno is set.
39 NOTES
40 The timeval structure has microsecond resolution, but in reality
41 this function has time resolution of 1 tick.
43 EXAMPLE
45 BUGS
46 Since AROS has no notion of last access time, it's silently ignored
47 and only modification time of the file is set.
49 SEE ALSO
50 utime()
52 INTERNALS
54 ******************************************************************************/
56 struct DateStamp ds;
58 if (!file) /*safety check */
60 errno = EFAULT;
61 return -1;
64 file = __path_u2a(file);
65 if (!file)
66 return -1;
68 if(tvp != NULL)
70 ULONG t = (ULONG)tvp[1].tv_sec - 2922 * 1440 * 60;
72 ds.ds_Days = t / (60*60*24);
73 ds.ds_Minute = (t / 60) % (60*24);
74 ds.ds_Tick = (t % 60) * TICKS_PER_SECOND;
76 else
77 DateStamp(&ds);
79 if (SetFileDate(file, &ds))
80 return 0;
81 else
82 errno = __arosc_ioerr2errno(IoErr());
84 return -1;