[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes |
Date: |
Sun, 19 May 2019 13:36:16 -0700 |
Cleaner to use ARRAY_SIZE to loop over elements instead of
using a sentinel within the data structure.
Signed-off-by: Richard Henderson <address@hidden>
---
linux-user/syscall-file.inc.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 961eed13ae..30f8e35cdd 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -235,7 +235,6 @@ static abi_long do_openat(void *cpu_env, int dirfd,
abi_ulong target_path,
int (*fill)(void *cpu_env, int fd);
int (*cmp)(const char *s1, const char *s2);
};
- const struct fake_open *fake_open;
static const struct fake_open fakes[] = {
{ "maps", open_self_maps, is_proc_myself },
{ "stat", open_self_stat, is_proc_myself },
@@ -244,12 +243,12 @@ static abi_long do_openat(void *cpu_env, int dirfd,
abi_ulong target_path,
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
{ "/proc/net/route", open_net_route, is_proc },
#endif
- { NULL, NULL, NULL }
};
char *pathname = lock_user_string(target_path);
int flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl);
abi_long ret;
+ size_t i;
if (!pathname) {
return -TARGET_EFAULT;
@@ -263,17 +262,16 @@ static abi_long do_openat(void *cpu_env, int dirfd,
abi_ulong target_path,
goto done;
}
- for (fake_open = fakes; fake_open->filename; fake_open++) {
- if (fake_open->cmp(pathname, fake_open->filename)) {
- break;
- }
- }
-
- if (fake_open->filename) {
+ for (i = 0; i < ARRAY_SIZE(fakes); ++i) {
+ const struct fake_open *fake_open = &fakes[i];
const char *tmpdir;
char filename[PATH_MAX];
int fd;
+ if (!fake_open->cmp(pathname, fake_open->filename)) {
+ continue;
+ }
+
/* create temporary file to map stat to */
tmpdir = getenv("TMPDIR");
if (!tmpdir) {
--
2.17.1
- [Qemu-devel] [PATCH v7 00/74] linux-user: Split do_syscall, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 03/74] linux-user: Share more code for open and openat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes,
Richard Henderson <=
- [Qemu-devel] [PATCH v7 02/74] linux-user: Split out open, open_at, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 01/74] linux-user: Setup split syscall infrastructure, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 05/74] linux-user: Split out readlink, readlinkat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 06/74] linux-user: Split out close, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 07/74] linux-user: Split out read, write, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 08/74] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 09/74] linux-user: Split out readv, writev, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 10/74] linux-user: Split out pread64, pwrite64, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 11/74] linux-user: Split out preadv, pwritev, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 12/74] linux-user: Split out name_to_handle_at, open_by_handle_at, Richard Henderson, 2019/05/19