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

Unified Diff: src/untrusted/nacl/utime.c

Issue 1065963002: Add utime implementation to libnacl (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Created 5 years, 8 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 | « src/untrusted/nacl/stubs/utime.c ('k') | tests/syscalls/syscalls.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/nacl/utime.c
diff --git a/src/untrusted/nacl/utime.c b/src/untrusted/nacl/utime.c
new file mode 100644
index 0000000000000000000000000000000000000000..e9985c30f296e47cc2af42bdde81a5e38de26ca7
--- /dev/null
+++ b/src/untrusted/nacl/utime.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2015 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <utime.h>
+
+/*
+ * TODO(sbc): remove this once utimes declaration gets added to the newlib
+ * headers.
+ */
+int utimes(const char *filename, const struct timeval tv[2]);
+
+/*
+ * Implementation of utime() based on utimes(). utime() works just like
+ * utimes() but only supports timestamps with a granularity of one second
+ * (time_t). This means we we can use utimes() to implement utime() by simply
+ * setting tv_usec fields to zero.
+ */
+int utime(const char *filename, const struct utimbuf *buf) {
+ struct timeval times[2];
+ struct timeval *tv = NULL;
+ if (buf != NULL) {
+ times[0].tv_sec = buf->actime;
+ times[1].tv_sec = buf->modtime;
+ times[0].tv_usec = 0;
+ times[1].tv_usec = 0;
+ tv = times;
+ }
+
+ return utimes(filename, tv);
+}
« no previous file with comments | « src/untrusted/nacl/stubs/utime.c ('k') | tests/syscalls/syscalls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698