From d43277c534904dc31d14bfb0dc934f3cfbe2dab5 Mon Sep 17 00:00:00 2001 From: Blue Swirl Date: Wed, 1 Jul 2009 18:24:44 +0000 Subject: [PATCH] Fix missing strnlen problems Fix missing strnlen (a GNU extension) problems by using qemu_strnlen used for user emulators also for system emulators. Signed-off-by: Blue Swirl --- block.c | 2 +- bsd-user/uaccess.c | 11 ----------- cutils.c | 13 +++++++++++++ linux-user/uaccess.c | 11 ----------- qemu-common.h | 1 + 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/block.c b/block.c index 3fe931702..c7589b1c2 100644 --- a/block.c +++ b/block.c @@ -225,7 +225,7 @@ static BlockDriver *find_protocol(const char *filename) { BlockDriver *drv1; char protocol[128]; - int len = strnlen(filename, 127)+1; + int len = qemu_strnlen(filename, 127) + 1; const char *p; #ifdef _WIN32 diff --git a/bsd-user/uaccess.c b/bsd-user/uaccess.c index cc51449b4..9ec1b2343 100644 --- a/bsd-user/uaccess.c +++ b/bsd-user/uaccess.c @@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len) return ret; } -/* XXX: use host strnlen if available ? */ -static int qemu_strnlen(const char *s, int max_len) -{ - int i; - for(i = 0; i < max_len; i++) { - if (s[i] == '\0') - break; - } - return i; -} - /* Return the length of a string in target memory or -TARGET_EFAULT if access error */ abi_long target_strlen(abi_ulong guest_addr1) diff --git a/cutils.c b/cutils.c index 73d4e1fbb..6196a9055 100644 --- a/cutils.c +++ b/cutils.c @@ -109,6 +109,19 @@ int stristart(const char *str, const char *val, const char **ptr) return 1; } +/* XXX: use host strnlen if available ? */ +int qemu_strnlen(const char *s, int max_len) +{ + int i; + + for(i = 0; i < max_len; i++) { + if (s[i] == '\0') { + break; + } + } + return i; +} + time_t mktimegm(struct tm *tm) { time_t t; diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c index 4d506935f..a4d108c2f 100644 --- a/linux-user/uaccess.c +++ b/linux-user/uaccess.c @@ -37,17 +37,6 @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len) return ret; } -/* XXX: use host strnlen if available ? */ -static int qemu_strnlen(const char *s, int max_len) -{ - int i; - for(i = 0; i < max_len; i++) { - if (s[i] == '\0') - break; - } - return i; -} - /* Return the length of a string in target memory or -TARGET_EFAULT if access error */ abi_long target_strlen(abi_ulong guest_addr1) diff --git a/qemu-common.h b/qemu-common.h index 5b8ac77f0..a5d8fffb7 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -109,6 +109,7 @@ void pstrcpy(char *buf, int buf_size, const char *str); char *pstrcat(char *buf, int buf_size, const char *s); int strstart(const char *str, const char *val, const char **ptr); int stristart(const char *str, const char *val, const char **ptr); +int qemu_strnlen(const char *s, int max_len); time_t mktimegm(struct tm *tm); int qemu_fls(int i); -- 2.39.2