diff --git a/fs/vfs/fs_chstat.c b/fs/vfs/fs_chstat.c index dc34591251..93c4db7e60 100644 --- a/fs/vfs/fs_chstat.c +++ b/fs/vfs/fs_chstat.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -301,15 +300,15 @@ int lchown(FAR const char *path, uid_t owner, gid_t group) } /**************************************************************************** - * Name: utimes + * Name: utimens * * Description: - * The utimes() function shall set the access and modification times of + * The utimens() function shall set the access and modification times of * the file pointed to by the path argument to the value of the times - * argument. utimes() function allows time specifications accurate to + * argument. utimens() function allows time specifications accurate to * the microsecond. * - * For utimes(), the times argument is an array of timeval structures. + * For utimens(), the times argument is an array of timeval structures. * The first array member represents the date and time of last access, * and the second member represents the date and time of last * modification. The times in the timeval structure are measured in @@ -320,7 +319,7 @@ int lchown(FAR const char *path, uid_t owner, gid_t group) * times of the file shall be set to the current time. The effective * user ID of the process shall match the owner of the file, has write * access to the file or appropriate privileges to use this call in this - * manner. Upon completion, utimes() shall mark the time of the last + * manner. Upon completion, utimens() shall mark the time of the last * file status change, st_ctime, for update. * * Input Parameters: @@ -334,14 +333,14 @@ int lchown(FAR const char *path, uid_t owner, gid_t group) * ****************************************************************************/ -int utimes(FAR const char *path, const struct timeval times[2]) +int utimens(FAR const char *path, const struct timespec times[2]) { struct stat buf; if (times != NULL) { - TIMEVAL_TO_TIMESPEC(×[0], &buf.st_atim); - TIMEVAL_TO_TIMESPEC(×[1], &buf.st_mtim); + buf.st_atim = times[0]; + buf.st_mtim = times[1]; } else { @@ -353,10 +352,10 @@ int utimes(FAR const char *path, const struct timeval times[2]) } /**************************************************************************** - * Name: lutimes + * Name: lutimens * * Description: - * The lutimes() system call is similar to utimes() but does not follow + * The lutimens() system call is similar to utimens() but does not follow * the symbolic links. * * Input Parameters: @@ -370,14 +369,14 @@ int utimes(FAR const char *path, const struct timeval times[2]) * ****************************************************************************/ -int lutimes(FAR const char *path, const struct timeval times[2]) +int lutimens(FAR const char *path, const struct timespec times[2]) { struct stat buf; if (times != NULL) { - TIMEVAL_TO_TIMESPEC(×[0], &buf.st_atim); - TIMEVAL_TO_TIMESPEC(×[1], &buf.st_mtim); + buf.st_atim = times[0]; + buf.st_mtim = times[1]; } else { diff --git a/include/sys/stat.h b/include/sys/stat.h index bb1fae0420..89c35da28b 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -178,6 +178,8 @@ int fstat(int fd, FAR struct stat *buf); int chmod(FAR const char *path, mode_t mode); int lchmod(FAR const char *path, mode_t mode); int fchmod(int fd, mode_t mode); +int utimens(FAR const char *path, const struct timespec times[2]); +int lutimens(FAR const char *path, const struct timespec times[2]); int futimens(int fd, const struct timespec times[2]); mode_t umask(mode_t mask); diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index b520a2f508..17268a549a 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -254,8 +254,8 @@ SYSCALL_LOOKUP(fchmod, 2) SYSCALL_LOOKUP(chown, 3) SYSCALL_LOOKUP(lchown, 3) SYSCALL_LOOKUP(fchown, 3) -SYSCALL_LOOKUP(utimes, 2) -SYSCALL_LOOKUP(lutimes, 2) +SYSCALL_LOOKUP(utimens, 2) +SYSCALL_LOOKUP(lutimens, 2) SYSCALL_LOOKUP(futimens, 2) #if defined(CONFIG_FS_RAMMAP) diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs index 4529c662b8..6a561bec51 100644 --- a/libs/libc/unistd/Make.defs +++ b/libs/libc/unistd/Make.defs @@ -26,9 +26,9 @@ CSRCS += lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c -CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utime.c +CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utime.c lib_utimes.c CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c -CSRCS += lib_futimes.c lib_gethostname.c lib_sethostname.c +CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c ifneq ($(CONFIG_SCHED_USER_IDENTITY),y) CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c diff --git a/libs/libc/unistd/lib_lutimes.c b/libs/libc/unistd/lib_lutimes.c new file mode 100644 index 0000000000..bc6f5ed4e1 --- /dev/null +++ b/libs/libc/unistd/lib_lutimes.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * libs/libc/unistd/lib_lutimes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int lutimes(FAR const char *path, const struct timeval tv[2]) +{ + struct timespec times[2]; + + if (tv == NULL) + { + return lutimens(path, NULL); + } + + times[0].tv_sec = tv[0].tv_sec; + times[0].tv_nsec = tv[0].tv_usec * 1000; + times[1].tv_sec = tv[1].tv_sec; + times[1].tv_nsec = tv[1].tv_usec * 1000; + + return lutimens(path, times); +} diff --git a/libs/libc/unistd/lib_utimes.c b/libs/libc/unistd/lib_utimes.c new file mode 100644 index 0000000000..5cb03af414 --- /dev/null +++ b/libs/libc/unistd/lib_utimes.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * libs/libc/unistd/lib_utimes.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int utimes(FAR const char *path, const struct timeval tv[2]) +{ + struct timespec times[2]; + + if (tv == NULL) + { + return utimens(path, NULL); + } + + times[0].tv_sec = tv[0].tv_sec; + times[0].tv_nsec = tv[0].tv_usec * 1000; + times[1].tv_sec = tv[1].tv_sec; + times[1].tv_nsec = tv[1].tv_usec * 1000; + + return utimens(path, times); +} diff --git a/syscall/syscall.csv b/syscall/syscall.csv index adcafe5313..fdd1b98d1e 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -56,7 +56,7 @@ "listen","sys/socket.h","defined(CONFIG_NET)","int","int","int" "lseek","unistd.h","","off_t","int","off_t","int" "lstat","sys/stat.h","","int","FAR const char *","FAR struct stat *" -"lutimes","sys/time.h","","int","FAR const char *","const struct timeval [2]|FAR const struct timeval *" +"lutimens","sys/stat.h","","int","FAR const char *","const struct timespec [2]|FAR const struct timespec *" "mkdir","sys/stat.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","mode_t" "mmap","sys/mman.h","","FAR void *","FAR void *","size_t","int","int","int","off_t" "modhandle","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *" @@ -189,7 +189,7 @@ "unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *" "unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "up_assert","nuttx/arch.h","","void","FAR const char *","int" -"utimes","sys/time.h","","int","FAR const char *","const struct timeval [2]|FAR const struct timeval *" +"utimens","sys/stat.h","","int","FAR const char *","const struct timespec [2]|FAR const struct timespec *" "vfork","unistd.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_ARCH_HAVE_VFORK)","pid_t" "wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","FAR int *" "waitid","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","int","idtype_t","id_t"," FAR siginfo_t *","int"