Re: [PATCH 1/9] util: make return value of virUUIDFormat and virMacAddrFormat useful

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

 



On Aug 5, 2012, at 12:16 AM, Laine Stump <laine@xxxxxxxxx> wrote:

> Both of these functions returned void, but it's convenient for them to
> return a const char* of the char* that is passed in. This was you can
> call the function and use the result in the same expression/arg.
> ---
> src/util/uuid.c       | 4 +++-
> src/util/uuid.h       | 6 +++---
> src/util/virmacaddr.c | 6 ++++--
> src/util/virmacaddr.h | 4 ++--
> 4 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/src/util/uuid.c b/src/util/uuid.c
> index 1efde69..be4b13a 100644
> --- a/src/util/uuid.c
> +++ b/src/util/uuid.c
> @@ -184,7 +184,8 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid) {
>  *
>  * Returns 0 in case of success and -1 in case of error.
>  */
> -void virUUIDFormat(const unsigned char *uuid, char *uuidstr)
> +const char *
> +virUUIDFormat(const unsigned char *uuid, char *uuidstr)
> {

The comment above the function says it returns 0 on success and -1 on error. Probably should be updated to match what it does now.


>     snprintf(uuidstr, VIR_UUID_STRING_BUFLEN,
>              "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
> @@ -193,6 +194,7 @@ void virUUIDFormat(const unsigned char *uuid, char *uuidstr)
>              uuid[8], uuid[9], uuid[10], uuid[11],
>              uuid[12], uuid[13], uuid[14], uuid[15]);
>     uuidstr[VIR_UUID_STRING_BUFLEN-1] = '\0';
> +    return uuidstr;
> }
> 
> 
> diff --git a/src/util/uuid.h b/src/util/uuid.h
> index da56a92..54e0573 100644
> --- a/src/util/uuid.h
> +++ b/src/util/uuid.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2007, 2011 Red Hat, Inc.
> + * Copyright (C) 2007, 2011, 2012 Red Hat, Inc.
>  *
>  * This library is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU Lesser General Public
> @@ -35,7 +35,7 @@ int virUUIDParse(const char *uuidstr,
>                  unsigned char *uuid)
>     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
> 
> -void virUUIDFormat(const unsigned char *uuid,
> -                   char *uuidstr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
> +const char *virUUIDFormat(const unsigned char *uuid,
> +                          char *uuidstr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
> 
> #endif /* __VIR_UUID_H__ */
> diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c
> index c07976b..341432c 100644
> --- a/src/util/virmacaddr.c
> +++ b/src/util/virmacaddr.c
> @@ -176,14 +176,16 @@ virMacAddrParse(const char* str, virMacAddrPtr addr)
>     return -1;
> }
> 
> -void virMacAddrFormat(const virMacAddrPtr addr,
> -                      char *str)
> +const char *
> +virMacAddrFormat(const virMacAddrPtr addr,
> +                 char *str)
> {
>     snprintf(str, VIR_MAC_STRING_BUFLEN,
>              "%02X:%02X:%02X:%02X:%02X:%02X",
>              addr->addr[0], addr->addr[1], addr->addr[2],
>              addr->addr[3], addr->addr[4], addr->addr[5]);
>     str[VIR_MAC_STRING_BUFLEN-1] = '\0';
> +    return str;
> }
> 
> void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
> diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h
> index fdac362..4c5074c 100644
> --- a/src/util/virmacaddr.h
> +++ b/src/util/virmacaddr.h
> @@ -44,8 +44,8 @@ int virMacAddrCmpRaw(const virMacAddrPtr mac1,
> void virMacAddrSet(virMacAddrPtr dst, const virMacAddrPtr src);
> void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char s[VIR_MAC_BUFLEN]);
> void virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN]);
> -void virMacAddrFormat(const virMacAddrPtr addr,
> -                      char *str);
> +const char *virMacAddrFormat(const virMacAddrPtr addr,
> +                             char *str);
> void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
>                         virMacAddrPtr addr);
> int virMacAddrParse(const char* str,
> -- 
> 1.7.11.2
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]