From 95ce6c9f8dab95cb9ce994add4870038b405a121 Mon Sep 17 00:00:00 2001 | |
From: Alexander von Gluck IV <kallisti5@unixzen.com> | |
Date: Thu, 16 Nov 2017 08:00:48 -0600 | |
Subject: [PATCH] libbsd: Move lutimes to bsd compat | |
* Rework be149e8ccf9 since lutimes isn't posix | |
--- | |
headers/compatibility/bsd/sys/time.h | 32 +++++++++++++++++++++++++ | |
headers/posix/sys/time.h | 1 - | |
src/libs/bsd/Jamfile | 1 + | |
src/libs/bsd/lutimes.c | 45 +++++++++++++++++++++++++++++++++++ | |
src/system/libroot/posix/sys/utimes.c | 26 -------------------- | |
5 files changed, 78 insertions(+), 27 deletions(-) | |
create mode 100644 headers/compatibility/bsd/sys/time.h | |
create mode 100644 src/libs/bsd/lutimes.c | |
diff --git a/headers/compatibility/bsd/sys/time.h b/headers/compatibility/bsd/sys/time.h | |
new file mode 100644 | |
index 0000000000..c986f62095 | |
--- /dev/null | |
+++ b/headers/compatibility/bsd/sys/time.h | |
@@ -0,0 +1,32 @@ | |
+/* | |
+ * Copyright 2016-2017 Haiku, Inc. All Rights Reserved. | |
+ * Distributed under the terms of the MIT License. | |
+ * | |
+ * Authors: | |
+ * Alexander von Gluck IV, kallisti5@unixzen.com | |
+ */ | |
+#ifndef _BSD_SYS_TIME_H_ | |
+#define _BSD_SYS_TIME_H_ | |
+ | |
+ | |
+#include_next <sys/time.h> | |
+ | |
+ | |
+#ifdef _BSD_SOURCE | |
+ | |
+ | |
+#ifdef __cplusplus | |
+extern "C" { | |
+#endif | |
+ | |
+int lutimes(const char *path, const struct timeval times[2]); | |
+ | |
+#ifdef __cplusplus | |
+} | |
+#endif | |
+ | |
+ | |
+#endif | |
+ | |
+ | |
+#endif /* _BSD_SYS_TIME_H_ */ | |
diff --git a/headers/posix/sys/time.h b/headers/posix/sys/time.h | |
index bb1277ddfe..dfa8d8cf23 100644 | |
--- a/headers/posix/sys/time.h | |
+++ b/headers/posix/sys/time.h | |
@@ -44,7 +44,6 @@ extern int setitimer(int which, const struct itimerval *value, struct itimerval | |
extern int gettimeofday(struct timeval *tv, void *tz); | |
extern int utimes(const char *path, const struct timeval times[2]); | |
-extern int lutimes(const char *path, const struct timeval times[2]); | |
/* legacy */ | |
#ifdef __cplusplus | |
diff --git a/src/libs/bsd/Jamfile b/src/libs/bsd/Jamfile | |
index d8e6c604a9..810ae74933 100644 | |
--- a/src/libs/bsd/Jamfile | |
+++ b/src/libs/bsd/Jamfile | |
@@ -16,6 +16,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { | |
fgetln.c | |
getpass.c | |
issetugid.c | |
+ lutimes.c | |
progname.c | |
pty.cpp | |
signal.c | |
diff --git a/src/libs/bsd/lutimes.c b/src/libs/bsd/lutimes.c | |
new file mode 100644 | |
index 0000000000..e3a5879755 | |
--- /dev/null | |
+++ b/src/libs/bsd/lutimes.c | |
@@ -0,0 +1,45 @@ | |
+/* | |
+ * Copyright, 2016-2017 Haiku, Inc. All rights reserved. | |
+ * Released under the terms of the MIT license. | |
+ * | |
+ * Authors: | |
+ * Alexander von Gluck IV, kallisti5@unixzen.com | |
+ * | |
+ */ | |
+ | |
+ | |
+#include <sys/time.h> | |
+ | |
+#include <errno.h> | |
+ | |
+#include <NodeMonitor.h> | |
+ | |
+#include <errno_private.h> | |
+#include <syscalls.h> | |
+//#include <syscall_utils.h> | |
+ | |
+ | |
+int | |
+lutimes(const char* path, const struct timeval times[2]) | |
+{ | |
+ struct stat stat; | |
+ status_t status; | |
+ | |
+ if (times != NULL) { | |
+ stat.st_atim.tv_sec = times[0].tv_sec; | |
+ stat.st_atim.tv_nsec = times[0].tv_usec * 1000; | |
+ | |
+ stat.st_mtim.tv_sec = times[1].tv_sec; | |
+ stat.st_mtim.tv_nsec = times[1].tv_usec * 1000; | |
+ } else { | |
+ bigtime_t now = real_time_clock_usecs(); | |
+ stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000; | |
+ stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000; | |
+ } | |
+ | |
+ // traverseLeafLink == false | |
+ status = _kern_write_stat(-1, path, false, &stat, sizeof(struct stat), | |
+ B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); | |
+ | |
+ RETURN_AND_SET_ERRNO(status); | |
+} | |
diff --git a/src/system/libroot/posix/sys/utimes.c b/src/system/libroot/posix/sys/utimes.c | |
index 09794ea3c4..f9721a3681 100644 | |
--- a/src/system/libroot/posix/sys/utimes.c | |
+++ b/src/system/libroot/posix/sys/utimes.c | |
@@ -42,32 +42,6 @@ utimes(const char* path, const struct timeval times[2]) | |
} | |
-int | |
-lutimes(const char* path, const struct timeval times[2]) | |
-{ | |
- struct stat stat; | |
- status_t status; | |
- | |
- if (times != NULL) { | |
- stat.st_atim.tv_sec = times[0].tv_sec; | |
- stat.st_atim.tv_nsec = times[0].tv_usec * 1000; | |
- | |
- stat.st_mtim.tv_sec = times[1].tv_sec; | |
- stat.st_mtim.tv_nsec = times[1].tv_usec * 1000; | |
- } else { | |
- bigtime_t now = real_time_clock_usecs(); | |
- stat.st_atim.tv_sec = stat.st_mtim.tv_sec = now / 1000000; | |
- stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000; | |
- } | |
- | |
- // traverseLeafLink == false | |
- status = _kern_write_stat(-1, path, false, &stat, sizeof(struct stat), | |
- B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); | |
- | |
- RETURN_AND_SET_ERRNO(status); | |
-} | |
- | |
- | |
int | |
utimensat(int fd, const char *path, const struct timespec times[2], int flag) | |
{ | |
-- | |
2.14.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment