1 /* vi: set sw=4 ts=4: */
2 /*
3  * utimes() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9 
10 #include <sys/syscall.h>
11 #include <sys/time.h>
12 
13 #if defined __NR_utimensat && !defined __NR_utimes
14 # include <fcntl.h>
15 # include <stddef.h>
utimes(const char * file,const struct timeval tvp[2])16 int utimes(const char *file, const struct timeval tvp[2])
17 {
18 	struct timespec ts[2], *times;
19 	if (tvp) {
20 		times = ts;
21 		times[0].tv_sec = tvp[0].tv_sec;
22 		times[0].tv_nsec = tvp[0].tv_usec * 1000;
23 		times[1].tv_sec = tvp[1].tv_sec;
24 		times[1].tv_nsec = tvp[1].tv_usec * 1000;
25 	} else {
26 		times = NULL;
27 	}
28 
29 	return utimensat(AT_FDCWD, file, times, 0);
30 }
31 
32 #elif defined __NR_utimes
33 _syscall2(int, utimes, const char *, file, const struct timeval *, tvp)
34 #elif defined __NR_utime
35 # define __need_NULL
36 # include <stddef.h>
37 # include <utime.h>
38 
39 int utimes(const char *file, const struct timeval tvp[2])
40 {
41 	struct utimbuf buf, *times;
42 
43 	if (tvp) {
44 		times = &buf;
45 		times->actime = tvp[0].tv_sec;
46 		times->modtime = tvp[1].tv_sec;
47 	} else {
48 		times = NULL;
49 	}
50 	return utime(file, times);
51 }
52 #endif
53 
54 #if defined __NR_utimensat || defined __NR_utimes || defined __NR_utime
55 libc_hidden_def(utimes)
56 #endif
57