ia64/xen-unstable

changeset 13687:1b32e279ddef

libelf cannot rely on the strlcpy() BSD-ism.
Make a private definition based on strncpy and strlen.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Jan 29 11:47:00 2007 +0000 (2007-01-29)
parents 5d9b72e640e0
children 5bb084098493
files xen/common/libelf/libelf-dominfo.c xen/common/libelf/libelf-private.h
line diff
     1.1 --- a/xen/common/libelf/libelf-dominfo.c	Mon Jan 29 10:55:20 2007 +0000
     1.2 +++ b/xen/common/libelf/libelf-dominfo.c	Mon Jan 29 11:47:00 2007 +0000
     1.3 @@ -128,16 +128,16 @@ int elf_xen_parse_note(struct elf_binary
     1.4      switch (type)
     1.5      {
     1.6      case XEN_ELFNOTE_LOADER:
     1.7 -	strlcpy(parms->loader, str, sizeof(parms->loader));
     1.8 +	elf_strlcpy(parms->loader, str, sizeof(parms->loader));
     1.9  	break;
    1.10      case XEN_ELFNOTE_GUEST_OS:
    1.11 -	strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
    1.12 +	elf_strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
    1.13  	break;
    1.14      case XEN_ELFNOTE_GUEST_VERSION:
    1.15 -	strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
    1.16 +	elf_strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
    1.17  	break;
    1.18      case XEN_ELFNOTE_XEN_VERSION:
    1.19 -	strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
    1.20 +	elf_strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
    1.21  	break;
    1.22      case XEN_ELFNOTE_PAE_MODE:
    1.23  	if (0 == strcmp(str, "yes"))
    1.24 @@ -224,13 +224,13 @@ int elf_xen_parse_guest_info(struct elf_
    1.25  
    1.26  	/* strings */
    1.27  	if (0 == strcmp(name, "LOADER"))
    1.28 -	    strlcpy(parms->loader, value, sizeof(parms->loader));
    1.29 +	    elf_strlcpy(parms->loader, value, sizeof(parms->loader));
    1.30  	if (0 == strcmp(name, "GUEST_OS"))
    1.31 -	    strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
    1.32 +	    elf_strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
    1.33  	if (0 == strcmp(name, "GUEST_VER"))
    1.34 -	    strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
    1.35 +	    elf_strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
    1.36  	if (0 == strcmp(name, "XEN_VER"))
    1.37 -	    strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
    1.38 +	    elf_strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
    1.39  	if (0 == strcmp(name, "PAE"))
    1.40  	{
    1.41  	    if (0 == strcmp(value, "yes[extended-cr3]"))
     2.1 --- a/xen/common/libelf/libelf-private.h	Mon Jan 29 10:55:20 2007 +0000
     2.2 +++ b/xen/common/libelf/libelf-private.h	Mon Jan 29 11:47:00 2007 +0000
     2.3 @@ -21,6 +21,8 @@
     2.4  #define bswap_32(x) swab32(x)
     2.5  #define bswap_64(x) swab64(x)
     2.6  
     2.7 +#define elf_strlcpy(d,s,c) strlcpy(d,s,c)
     2.8 +
     2.9  #else /* !__XEN__ */
    2.10  
    2.11  #include <stdio.h>
    2.12 @@ -50,6 +52,14 @@
    2.13          xc_set_error(XC_INVALID_KERNEL, fmt , ## args );  \
    2.14  	} while (0)
    2.15  
    2.16 +/* SysV unices have no strlcpy/strlcat. */
    2.17 +static inline size_t elf_strlcpy(char *dest, const char *src, size_t size)
    2.18 +{
    2.19 +    strncpy(dest, src, size-1);
    2.20 +    dest[size-1] = '\0';
    2.21 +    return strlen(src);
    2.22 +}
    2.23 +
    2.24  #endif
    2.25  
    2.26  #endif /* __LIBELF_PRIVATE_H_ */