diff options
author | sbc <sbc@chromium.org> | 2015-07-24 16:12:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-24 23:12:53 +0000 |
commit | a16338aab059480a3f120644c42aef5c03629f46 (patch) | |
tree | 3d142c0a4a46bbb6e636d720e69f33d6d7af83c7 /native_client_sdk | |
parent | 2b37330184b76cc7a478a4083afb0fb459ff99af (diff) | |
download | chromium_src-a16338aab059480a3f120644c42aef5c03629f46.zip chromium_src-a16338aab059480a3f120644c42aef5c03629f46.tar.gz chromium_src-a16338aab059480a3f120644c42aef5c03629f46.tar.bz2 |
[NaCl SDK] nacl_io: consistent used of dirent structure
Use struct direct rather than void* where possible and
remove duplicate declaration of nacl_abi_dirent.
Review URL: https://codereview.chromium.org/1214163004
Cr-Commit-Position: refs/heads/master@{#340369}
Diffstat (limited to 'native_client_sdk')
9 files changed, 52 insertions, 66 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc index 73bd907..f7073b0 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc @@ -242,7 +242,7 @@ int ki_fstat(int fd, struct stat* buf) { KP_CALL(fstat, (fd, buf)); } -int ki_getdents(int fd, void* buf, unsigned int count) { +int ki_getdents(int fd, struct dirent* buf, unsigned int count) { KP_CALL(getdents, (fd, buf, count)); } diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h index 463747e..8a4e505 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h +++ b/native_client_sdk/src/libraries/nacl_io/kernel_intercept.h @@ -5,6 +5,7 @@ #ifndef LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ #define LIBRARIES_NACL_IO_KERNEL_INTERCEPT_H_ +#include <dirent.h> #include <stdarg.h> #include <sys/time.h> @@ -90,7 +91,7 @@ int ki_pipe(int pipefds[2]); ssize_t ki_read(int fd, void* buf, size_t nbyte); ssize_t ki_write(int fd, const void* buf, size_t nbyte); int ki_fstat(int fd, struct stat* buf); -int ki_getdents(int fd, void* buf, unsigned int count); +int ki_getdents(int fd, struct dirent* buf, unsigned int count); int ki_fsync(int fd); int ki_fdatasync(int fd); int ki_ftruncate(int fd, off_t length); diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc index b510f05..de94f27 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc @@ -591,7 +591,7 @@ int KernelProxy::fstat(int fd, struct stat* buf) { return 0; } -int KernelProxy::getdents(int fd, void* buf, unsigned int count) { +int KernelProxy::getdents(int fd, struct dirent* buf, unsigned int count) { ScopedKernelHandle handle; Error error = AcquireHandle(fd, &handle); if (error) { @@ -600,7 +600,7 @@ int KernelProxy::getdents(int fd, void* buf, unsigned int count) { } int cnt = 0; - error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt); + error = handle->GetDents(buf, count, &cnt); if (error) errno = error; diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h index ddec6d7..669031d 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h +++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.h @@ -110,7 +110,7 @@ class KernelProxy : protected KernelObject { virtual int fchmod(int fd, mode_t mode); virtual int fcntl(int fd, int request, va_list args); virtual int fstat(int fd, struct stat* buf); - virtual int getdents(int fd, void* buf, unsigned int count); + virtual int getdents(int fd, struct dirent* buf, unsigned int count); virtual int fchdir(int fd); virtual int ftruncate(int fd, off_t length); virtual int fsync(int fd); diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc index 4d9f6fc..43398b5 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_bionic.cc @@ -23,6 +23,7 @@ #include "nacl_io/kernel_intercept.h" #include "nacl_io/kernel_wrap_real.h" +#include "nacl_io/nacl_abi_dirent.h" #include "nacl_io/osmman.h" namespace { @@ -63,36 +64,6 @@ void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) { } // namespace -// From native_client/src/trusted/service_runtime/include/sys/dirent.h - -#ifndef nacl_abi___ino_t_defined -#define nacl_abi___ino_t_defined -typedef int64_t nacl_abi___ino_t; -typedef nacl_abi___ino_t nacl_abi_ino_t; -#endif - -#ifndef nacl_abi___off_t_defined -#define nacl_abi___off_t_defined -typedef int64_t nacl_abi__off_t; -typedef nacl_abi__off_t nacl_abi_off_t; -#endif - -/* We need a way to define the maximum size of a name. */ -#ifndef MAXNAMLEN -# ifdef NAME_MAX -# define MAXNAMLEN NAME_MAX -# else -# define MAXNAMLEN 255 -# endif -#endif - -struct nacl_abi_dirent { - nacl_abi_ino_t nacl_abi_d_ino; - nacl_abi_off_t nacl_abi_d_off; - uint16_t nacl_abi_d_reclen; - char nacl_abi_d_name[MAXNAMLEN + 1]; -}; - static const int d_name_shift = offsetof (dirent, d_name) - offsetof (struct nacl_abi_dirent, nacl_abi_d_name); diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc index 6e9ef19..0fda3bc4 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc @@ -22,6 +22,7 @@ #include "nacl_io/kernel_intercept.h" #include "nacl_io/kernel_wrap_real.h" #include "nacl_io/log.h" +#include "nacl_io/nacl_abi_dirent.h" #include "nacl_io/osmman.h" #include "nacl_io/ostime.h" @@ -69,36 +70,6 @@ void nacl_stat_to_stat(const nacl_abi_stat* nacl_buf, struct stat* buf) { } // namespace -// From native_client/src/trusted/service_runtime/include/sys/dirent.h - -#ifndef nacl_abi___ino_t_defined -#define nacl_abi___ino_t_defined -typedef int64_t nacl_abi___ino_t; -typedef nacl_abi___ino_t nacl_abi_ino_t; -#endif - -#ifndef nacl_abi___off_t_defined -#define nacl_abi___off_t_defined -typedef int64_t nacl_abi__off_t; -typedef nacl_abi__off_t nacl_abi_off_t; -#endif - -/* We need a way to define the maximum size of a name. */ -#ifndef MAXNAMLEN -# ifdef NAME_MAX -# define MAXNAMLEN NAME_MAX -# else -# define MAXNAMLEN 255 -# endif -#endif - -struct nacl_abi_dirent { - nacl_abi_ino_t nacl_abi_d_ino; - nacl_abi_off_t nacl_abi_d_off; - uint16_t nacl_abi_d_reclen; - char nacl_abi_d_name[MAXNAMLEN + 1]; -}; - static const int d_name_shift = offsetof (dirent, d_name) - offsetof (struct nacl_abi_dirent, nacl_abi_d_name); @@ -237,7 +208,8 @@ int WRAP(getdents)(int fd, dirent* nacl_buf, size_t nacl_count, size_t* nread) { while (offset < count) { dirent* d = (dirent*)(buf + offset); - nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)((char*)nacl_buf + nacl_offset); + nacl_abi_dirent* nacl_d = static_cast<nacl_abi_dirent*>( + (char*)nacl_buf + nacl_offset); nacl_d->nacl_abi_d_ino = d->d_ino; nacl_d->nacl_abi_d_off = d->d_off; nacl_d->nacl_abi_d_reclen = d->d_reclen - d_name_shift; diff --git a/native_client_sdk/src/libraries/nacl_io/library.dsc b/native_client_sdk/src/libraries/nacl_io/library.dsc index 40aa14a..e546159 100644 --- a/native_client_sdk/src/libraries/nacl_io/library.dsc +++ b/native_client_sdk/src/libraries/nacl_io/library.dsc @@ -171,6 +171,7 @@ "ioctl.h", "jsfs/js_fs.h", "jsfs/js_fs_node.h", + "nacl_abi_dirent.h", "kernel_handle.h", "kernel_intercept.h", "kernel_object.h", diff --git a/native_client_sdk/src/libraries/nacl_io/nacl_abi_dirent.h b/native_client_sdk/src/libraries/nacl_io/nacl_abi_dirent.h new file mode 100644 index 0000000..b3e3c7b --- /dev/null +++ b/native_client_sdk/src/libraries/nacl_io/nacl_abi_dirent.h @@ -0,0 +1,40 @@ +/* Copyright 2015 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ + +#ifndef LIBRARIES_NACL_IO_NACL_ABI_DIRENT_H_ +#define LIBRARIES_NACL_IO_NACL_ABI_DIRENT_H_ + +#include <dirent.h> + +/* From native_client/src/trusted/service_runtime/include/sys/dirent.h */ + +#ifndef nacl_abi___ino_t_defined +#define nacl_abi___ino_t_defined +typedef int64_t nacl_abi___ino_t; +typedef nacl_abi___ino_t nacl_abi_ino_t; +#endif + +#ifndef nacl_abi___off_t_defined +#define nacl_abi___off_t_defined +typedef int64_t nacl_abi__off_t; +typedef nacl_abi__off_t nacl_abi_off_t; +#endif + +/* We need a way to define the maximum size of a name. */ +#ifndef MAXNAMLEN +# ifdef NAME_MAX +# define MAXNAMLEN NAME_MAX +# else +# define MAXNAMLEN 255 +# endif +#endif + +struct nacl_abi_dirent { + nacl_abi_ino_t nacl_abi_d_ino; + nacl_abi_off_t nacl_abi_d_off; + uint16_t nacl_abi_d_reclen; + char nacl_abi_d_name[MAXNAMLEN + 1]; +}; + +#endif /* LIBRARIES_NACL_IO_NACL_ABI_DIRENT_H_ */ diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc index c46065e..4143129 100644 --- a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc +++ b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc @@ -23,6 +23,7 @@ #include "nacl_io/kernel_intercept.h" #include "nacl_io/kernel_proxy.h" #include "nacl_io/memfs/mem_fs.h" +#include "nacl_io/nacl_abi_dirent.h" #include "nacl_io/osmman.h" #include "nacl_io/ostime.h" #include "nacl_io/path.h" |