summaryrefslogtreecommitdiffstats
path: root/lib/util
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-12-16 11:21:22 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-12-18 09:52:42 +0800
commit675d604772d99346e804b120c0c27cced985899a (patch)
tree3b703f7ea1633cddcaf8171a1d1b9a3eada80b4e /lib/util
parent072847109936bc0e822f8cf67c31eb62183f0db8 (diff)
downloadtalos-petitboot-675d604772d99346e804b120c0c27cced985899a.tar.gz
talos-petitboot-675d604772d99346e804b120c0c27cced985899a.zip
lib/util: Avoid sprintf in mac_str
The conversion is simple, no need for sprintf. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/util.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 75b1c23..a18926c 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -15,12 +15,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <util/util.h>
+static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
+
void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
{
unsigned int i;
@@ -36,8 +38,9 @@ void mac_str(uint8_t *mac, unsigned int maclen, char *buf, unsigned int buflen)
pos = buf;
for (i = 0; i < maclen; i++) {
- snprintf(pos, 4, "%02x:", mac[i]);
- pos += 3;
+ *(pos++) = hex[mac[i] >> 4 & 0xf];
+ *(pos++) = hex[mac[i] & 0xf];
+ *(pos++) = ':';
}
*(pos - 1) = '\0';
OpenPOWER on IntegriCloud