Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1471)

Unified Diff: base/os_compat_android.cc

Issue 14649009: Android: Provide futimes() implementation using utimensat() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: validate timeval input Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/os_compat_android.cc
diff --git a/base/os_compat_android.cc b/base/os_compat_android.cc
index c4ea463d1781a4fba039e323e90bf39ee276b52d..2f5b4db44c02f16f179802af0c37906ff24719d4 100644
--- a/base/os_compat_android.cc
+++ b/base/os_compat_android.cc
@@ -4,22 +4,37 @@
#include "base/os_compat_android.h"
+#include <asm/unistd.h>
#include <errno.h>
#include <math.h>
#include <sys/stat.h>
+#include <sys/syscall.h>
#include <time64.h>
#include "base/rand_util.h"
#include "base/stringprintf.h"
#include "base/strings/string_piece.h"
+extern "C" {
// There is no futimes() avaiable in Bionic, so we provide our own
// implementation until it is there.
-extern "C" {
-
int futimes(int fd, const struct timeval tv[2]) {
- const std::string fd_path = base::StringPrintf("/proc/self/fd/%d", fd);
- return utimes(fd_path.c_str(), tv);
+ if (tv == NULL)
+ return syscall(__NR_utimensat, fd, NULL, NULL, 0);
+
+ if (tv[0].tv_usec < 0 || tv[0].tv_usec >= 1000000 ||
+ tv[1].tv_usec < 0 || tv[1].tv_usec >= 1000000) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ // Convert timeval to timespec.
+ struct timespec ts[2];
+ ts[0].tv_sec = tv[0].tv_sec;
+ ts[0].tv_nsec = tv[0].tv_usec * 1000;
+ ts[1].tv_sec = tv[1].tv_sec;
+ ts[1].tv_nsec = tv[1].tv_usec * 1000;
+ return syscall(__NR_utimensat, fd, NULL, ts, 0);
}
// Android has only timegm64() and no timegm().
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698