| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory | 8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory |
| 9 * mapping using descriptors. | 9 * mapping using descriptors. |
| 10 * | 10 * |
| 11 * Note that we avoid using the thread-specific data / thread local | 11 * Note that we avoid using the thread-specific data / thread local |
| 12 * storage access to the "errno" variable, and instead use the raw | 12 * storage access to the "errno" variable, and instead use the raw |
| 13 * system call return interface of small negative numbers as errors. | 13 * system call return interface of small negative numbers as errors. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include <stdint.h> | 16 #include <stdint.h> |
| 17 #include <stdio.h> | 17 #include <stdio.h> |
| 18 #include <sys/types.h> | 18 #include <sys/types.h> |
| 19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
| 20 #include <fcntl.h> | 20 #include <fcntl.h> |
| 21 #include <errno.h> | 21 #include <errno.h> |
| 22 #include <sys/mman.h> | 22 #include <sys/mman.h> |
| 23 #include <unistd.h> | 23 #include <unistd.h> |
| 24 #include <utime.h> |
| 24 | 25 |
| 25 #include "native_client/src/include/build_config.h" | 26 #include "native_client/src/include/build_config.h" |
| 26 | 27 |
| 27 #if NACL_LINUX | 28 #if NACL_LINUX |
| 28 # include <pthread.h> | 29 # include <pthread.h> |
| 29 /* pthread_once for NaClHostDescInit, which is no-op on other OSes */ | 30 /* pthread_once for NaClHostDescInit, which is no-op on other OSes */ |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #include "native_client/src/include/nacl_platform.h" | 33 #include "native_client/src/include/nacl_platform.h" |
| 33 #include "native_client/src/include/portability.h" | 34 #include "native_client/src/include/portability.h" |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 return -NaClXlateErrno(errno); | 713 return -NaClXlateErrno(errno); |
| 713 return 0; | 714 return 0; |
| 714 } | 715 } |
| 715 | 716 |
| 716 int NaClHostDescReadlink(const char *path, char *buf, size_t bufsize) { | 717 int NaClHostDescReadlink(const char *path, char *buf, size_t bufsize) { |
| 717 int retval = readlink(path, buf, bufsize); | 718 int retval = readlink(path, buf, bufsize); |
| 718 if (retval < 0) | 719 if (retval < 0) |
| 719 return -NaClXlateErrno(errno); | 720 return -NaClXlateErrno(errno); |
| 720 return retval; | 721 return retval; |
| 721 } | 722 } |
| 723 |
| 724 int NaClHostDescUtimes(const char *filename, |
| 725 const struct nacl_abi_timeval times[2]) { |
| 726 struct timeval host_times[2]; |
| 727 if (times != NULL) { |
| 728 host_times[0].tv_sec = times[0].nacl_abi_tv_sec; |
| 729 host_times[0].tv_usec = times[0].nacl_abi_tv_usec; |
| 730 host_times[1].tv_sec = times[1].nacl_abi_tv_sec; |
| 731 host_times[1].tv_usec = times[1].nacl_abi_tv_usec; |
| 732 } |
| 733 if (-1 == utimes(filename, (times != NULL ? host_times : NULL))) { |
| 734 return -NaClXlateErrno(errno); |
| 735 } |
| 736 return 0; |
| 737 } |
| 738 |
| 739 int NaClHostDescFchdir(struct NaClHostDesc *d) { |
| 740 NaClHostDescCheckValidity("NaClHostDescFchdir", d); |
| 741 if (-1 == fchdir(d->d)) { |
| 742 return -NaClXlateErrno(errno); |
| 743 } |
| 744 return 0; |
| 745 } |
| 746 |
| 747 int NaClHostDescFchmod(struct NaClHostDesc *d, nacl_abi_mode_t mode) { |
| 748 NaClHostDescCheckValidity("NaClHostDescFchmod", d); |
| 749 if (-1 == fchmod(d->d, mode)) { |
| 750 return -NaClXlateErrno(errno); |
| 751 } |
| 752 return 0; |
| 753 } |
| 754 |
| 755 int NaClHostDescFsync(struct NaClHostDesc *d) { |
| 756 NaClHostDescCheckValidity("NaClHostDescFsync", d); |
| 757 if (-1 == fsync(d->d)) { |
| 758 return -NaClXlateErrno(errno); |
| 759 } |
| 760 return 0; |
| 761 } |
| 762 |
| 763 int NaClHostDescFdatasync(struct NaClHostDesc *d) { |
| 764 NaClHostDescCheckValidity("NaClHostDescFdatasync", d); |
| 765 if (-1 == fdatasync(d->d)) { |
| 766 return -NaClXlateErrno(errno); |
| 767 } |
| 768 return 0; |
| 769 } |
| 770 |
| 771 int NaClHostDescFtruncate(struct NaClHostDesc *d, nacl_off64_t length) { |
| 772 NaClHostDescCheckValidity("NaClHostDescFtruncate", d); |
| 773 #if NACL_LINUX |
| 774 if (-1 == ftruncate64(d->d, length)) { |
| 775 return -NaClXlateErrno(errno); |
| 776 } |
| 777 #elif NACL_OSX |
| 778 if (-1 == ftruncate(d->d, length)) { |
| 779 return -NaClXlateErrno(errno); |
| 780 } |
| 781 #else |
| 782 # error Unsupported platform |
| 783 #endif |
| 784 return 0; |
| 785 } |
| OLD | NEW |