blob: e01d40efd8ad32f83da3c5a13fca66f165cd6110 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* vi: set sw=4 ts=4: */
2/*
3 * lutimes() implementation for uClibc
4 *
5 * Copyright (C) 2010 Vladimir Zapolskiy <vzapolskiy@gmail.com>
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 <time.h>
12
13#ifdef __NR_lutimes
14_syscall2(int, lutimes, const char *, file, const struct timeval *, tvp)
15#elif defined __NR_utimensat
16#include <sys/time.h>
17#include <fcntl.h>
18
19int lutimes(const char *file, const struct timeval tvp[2])
20{
21 struct timespec ts[2];
22
23 if (tvp != NULL)
24 {
25 if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
26 || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
27 {
28 __set_errno(EINVAL);
29 return -1;
30 }
31
32 TIMEVAL_TO_TIMESPEC(&tvp[0], &ts[0]);
33 TIMEVAL_TO_TIMESPEC(&tvp[1], &ts[1]);
34 }
35
36 return utimensat(AT_FDCWD, file, tvp ? ts : NULL, AT_SYMLINK_NOFOLLOW);
37}
38#endif