Chromium Code Reviews| 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..628900ae3e1213f9921e17d24b139d7c9aacacd3 |
| --- /dev/null |
| +++ b/src/untrusted/nacl/utime.c |
| @@ -0,0 +1,45 @@ |
| +/* |
| + * 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 <sys/types.h> |
| +#include <utime.h> |
| +#include <sys/time.h> |
| +#include <errno.h> |
|
Mark Seaborn
2015/04/07 19:08:43
Sort #includes
Sam Clegg
2015/04/10 21:18:55
Done.
|
| +#include <stdio.h> |
|
Mark Seaborn
2015/04/07 19:08:43
Not needed
Sam Clegg
2015/04/10 21:18:56
Done.
|
| + |
| +#include "native_client/src/untrusted/nacl/nacl_irt.h" |
|
Mark Seaborn
2015/04/07 19:08:43
Not needed with the change below...
Sam Clegg
2015/04/10 21:18:55
Done.
|
| + |
| +/* |
| + * Implementation of utime based on the utimes IRT function. utime works |
| + * just like utimes but only support timestamps with a granularity of one |
| + * second (support time_t). This means we we can use utimes to impelement |
|
Mark Seaborn
2015/04/07 19:08:43
What do you mean by "support time_t"? Can you rem
Sam Clegg
2015/04/10 21:18:56
Done.
|
| + * utime by simply setting tv_sec fields to zero. |
| + */ |
| +int utime(const char *filename, const struct utimbuf *buf) { |
| + if (!__libnacl_irt_init_fn(&__libnacl_irt_dev_filename.utimes, |
| + __libnacl_irt_dev_filename_init)) { |
| + return -1; |
| + } |
| + |
| + struct timeval times[2]; |
| + struct timeval* tv = NULL; |
|
Mark Seaborn
2015/04/07 19:08:43
Use " *" spacing
Sam Clegg
2015/04/10 21:18:55
Done.
|
| + 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; |
| + } |
| + |
| + int error = __libnacl_irt_dev_filename.utimes(filename, tv); |
|
Mark Seaborn
2015/04/07 19:08:43
Just call utimes() instead of getting the IRT inte
Sam Clegg
2015/04/10 21:18:55
Done.
|
| + if (error) { |
| + errno = error; |
| + return -1; |
| + } |
| + |
| + return 0; |
| +} |