]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: make return value of virUUIDFormat and virMacAddrFormat useful
authorLaine Stump <laine@laine.org>
Thu, 2 Aug 2012 18:06:58 +0000 (14:06 -0400)
committerLaine Stump <laine@laine.org>
Tue, 14 Aug 2012 19:47:02 +0000 (15:47 -0400)
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
src/util/uuid.h
src/util/virmacaddr.c
src/util/virmacaddr.h

index 1efde693afabd7787cb83d3b2f9dbccc902efc2f..54e7bb6766678157299be983540900e43a19cd69 100644 (file)
@@ -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;
 }
 
 
index da56a92aea7cb3a7ed3a63582aa65b82c83af3ab..54e0573ef863b128eda4b718a296de34c7be014e 100644 (file)
@@ -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__ */
index c07976beb3c0abba0719638c5bbe842c17ac2894..e20792711299cd3c5b92a7e1584486e47daea63d 100644 (file)
@@ -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],
index fdac362f03147c04b8095c9686f7243c490eec72..4c5074ce3c60dc007bd21839437560a6e66d7b3b 100644 (file)
@@ -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,