summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAriel Don <ariel@arieldon.com>2022-05-03 14:52:08 -0500
committerAndreas Kling <kling@serenityos.org>2022-05-21 18:15:00 +0200
commit8a854ba309a591254935559e72c44dca98c9a05e (patch)
tree208f35ac2b6576835311a6314749cf395716bab6 /Userland/Libraries
parent9a6bd859243df604c1b1f1762bb701165917f367 (diff)
downloadserenity-8a854ba309a591254935559e72c44dca98c9a05e.zip
Kernel+LibC: Implement futimens(3)
Implement futimes() in terms of utimensat(). Now, utimensat() strays from POSIX compliance because it also accepts a combination of a file descriptor of a regular file and an empty path. utimensat() then uses this file descriptor instead of the path to update the last access and/or modification time of a file. That being said, its prior behavior remains intact. With the new behavior of utimensat(), `path` must point to a valid string; given a null pointer instead of an empty string, utimensat() sets `errno` to `EFAULT` and returns a failure.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibC/stat.cpp6
-rw-r--r--Userland/Libraries/LibC/sys/stat.h1
2 files changed, 7 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/stat.cpp b/Userland/Libraries/LibC/stat.cpp
index bcb52fd898..d1ce13ea90 100644
--- a/Userland/Libraries/LibC/stat.cpp
+++ b/Userland/Libraries/LibC/stat.cpp
@@ -109,4 +109,10 @@ int fstatat(int fd, char const* path, struct stat* statbuf, int flags)
{
return do_stat(fd, path, statbuf, !(flags & AT_SYMLINK_NOFOLLOW));
}
+
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html
+int futimens(int fd, struct timespec const times[2])
+{
+ return utimensat(fd, "", times, 0);
+}
}
diff --git a/Userland/Libraries/LibC/sys/stat.h b/Userland/Libraries/LibC/sys/stat.h
index 4ada805708..16b8a2c2e8 100644
--- a/Userland/Libraries/LibC/sys/stat.h
+++ b/Userland/Libraries/LibC/sys/stat.h
@@ -23,5 +23,6 @@ int fstat(int fd, struct stat* statbuf);
int lstat(char const* path, struct stat* statbuf);
int stat(char const* path, struct stat* statbuf);
int fstatat(int fd, char const* path, struct stat* statbuf, int flags);
+int futimens(int fd, struct timespec const times[2]);
__END_DECLS