typo
[AROS.git] / compiler / posixc / utimes.c
blobf6199005efabc754f699ff8fa680b414743d381c
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 utimes() function
6 */
8 #include <dos/dos.h>
9 #include <proto/dos.h>
11 #include <errno.h>
13 #include "__upath.h"
15 /*****************************************************************************
17 NAME */
18 #include <sys/time.h>
20 int utimes(
21 /* SYNOPSIS */
23 const char *file,
24 const struct timeval tvp[2])
26 /* FUNCTION
27 Change last access and last modification time of the given file to
28 times specified in tvp array. If tvp is NULL, the current time will be
29 used instead.
31 INPUTS
32 filename - Name of the file
33 buf - Pointer to an array of two timeval structures. First structure
34 specifies the last access time, second specifies the last
35 modification time
37 RESULT
38 0 on success and -1 on error. If an error occurred, the global
39 variable errno is set.
41 NOTES
42 The timeval structure has microsecond resolution, but in reality
43 this function has time resolution of 1 tick.
45 EXAMPLE
47 BUGS
48 Since AROS has no notion of last access time, it's silently ignored
49 and only modification time of the file is set.
51 SEE ALSO
52 utime()
54 INTERNALS
56 ******************************************************************************/
58 struct DateStamp ds;
60 if (!file) /*safety check */
62 errno = EFAULT;
63 return -1;
66 file = __path_u2a(file);
67 if (!file)
68 return -1;
70 if(tvp != NULL)
72 ULONG t = (ULONG)tvp[1].tv_sec - 2922 * 1440 * 60;
74 ds.ds_Days = t / (60*60*24);
75 ds.ds_Minute = (t / 60) % (60*24);
76 ds.ds_Tick = (t % 60) * TICKS_PER_SECOND;
78 else
79 DateStamp(&ds);
81 if (SetFileDate(file, &ds))
82 return 0;
83 else
84 errno = __stdc_ioerr2errno(IoErr());
86 return -1;