Skip to content

Commit

Permalink
Fix missing strnlen problems
Browse files Browse the repository at this point in the history
Fix missing strnlen (a GNU extension) problems by using qemu_strnlen
used for user emulators also for system emulators.

Signed-off-by: Blue Swirl <[email protected]>
  • Loading branch information
blueswirl committed Jul 1, 2009
1 parent 57a943c commit d43277c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions bsd-user/uaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions linux-user/uaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions qemu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d43277c

Please sign in to comment.