mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
util: make return value of virUUIDFormat and virMacAddrFormat useful
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.
This commit is contained in:
parent
37f3cd416c
commit
85d9c17d70
@ -182,9 +182,10 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid) {
|
||||
*
|
||||
* Converts the raw UUID into printable format, with embedded '-'
|
||||
*
|
||||
* Returns 0 in case of success and -1 in case of error.
|
||||
* Returns a pointer to the resulting character string.
|
||||
*/
|
||||
void virUUIDFormat(const unsigned char *uuid, char *uuidstr)
|
||||
const char *
|
||||
virUUIDFormat(const unsigned char *uuid, char *uuidstr)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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__ */
|
||||
|
@ -176,14 +176,23 @@ virMacAddrParse(const char* str, virMacAddrPtr addr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void virMacAddrFormat(const virMacAddrPtr addr,
|
||||
char *str)
|
||||
/* virMacAddrFormat
|
||||
* Converts the binary mac address in addr into a NULL-terminated
|
||||
* character string in str. It is assumed that the memory pointed to
|
||||
* by str is at least VIR_MAC_STRING_BUFLEN bytes long.
|
||||
*
|
||||
* Returns a pointer to the resulting character string.
|
||||
*/
|
||||
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],
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user