Re: [kvm-unit-tests PATCH 1/2] lib/string: add strncmp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11/05/2016 22:55, Radim Krčmář wrote:
> Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx>
> Signed-off-by: Radim Krčmář <rkrcmar@xxxxxxxxxx>

Reviewed-by: Laurent Vivier <lvivier@xxxxxxxxxx>

> ---
>  lib/string.c | 17 ++++++++++-------
>  lib/string.h |  1 +
>  2 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/string.c b/lib/string.c
> index e7bcfe945fcf..ee93e25e9821 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -26,15 +26,18 @@ char *strcpy(char *dest, const char *src)
>      return strcat(dest, src);
>  }
>  
> +int strncmp(const char *a, const char *b, size_t n)
> +{
> +    for (; n--; ++a, ++b)
> +        if (*a != *b || *a == '\0')
> +            return *a - *b;
> +
> +    return 0;
> +}
> +
>  int strcmp(const char *a, const char *b)
>  {
> -    while (*a == *b) {
> -	if (*a == '\0') {
> -	    break;
> -	}
> -	++a, ++b;
> -    }
> -    return *a - *b;
> +    return strncmp(a, b, SIZE_MAX);
>  }
>  
>  char *strchr(const char *s, int c)
> diff --git a/lib/string.h b/lib/string.h
> index 4e24f54d9e23..2391013ad2b1 100644
> --- a/lib/string.h
> +++ b/lib/string.h
> @@ -5,6 +5,7 @@ extern unsigned long strlen(const char *buf);
>  extern char *strcat(char *dest, const char *src);
>  extern char *strcpy(char *dest, const char *src);
>  extern int strcmp(const char *a, const char *b);
> +extern int strncmp(const char *a, const char *b, size_t n);
>  extern char *strchr(const char *s, int c);
>  extern char *strstr(const char *haystack, const char *needle);
>  extern void *memset(void *s, int c, size_t n);
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux