X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Futil.c;h=b1925f0e207f5a41686fe7f5d81d5ac1e285d9bf;hb=7ba2b1fcc731085127c9976b1bae4aaaa5b8b7a7;hp=514f0d9a07f3de6cedf80a2cf652c5e4dfdeac61;hpb=5ebf655c85076f200955458673a8bbf0dd927407;p=catta diff --git a/avahi-core/util.c b/avahi-core/util.c index 514f0d9..b1925f0 100644 --- a/avahi-core/util.c +++ b/avahi-core/util.c @@ -27,16 +27,16 @@ #include #include #include +#include -#include - +#include #include "util.h" void avahi_hexdump(const void* p, size_t size) { const uint8_t *c = p; assert(p); - printf("Dumping %u bytes from %p:\n", size, p); + printf("Dumping %lu bytes from %p:\n", (unsigned long) size, p); while (size > 0) { unsigned i; @@ -66,28 +66,57 @@ void avahi_hexdump(const void* p, size_t size) { } } - -char *avahi_format_mac_address(const uint8_t* mac, size_t size) { - char *r, *t; +char *avahi_format_mac_address(char *r, size_t l, const uint8_t* mac, size_t size) { + char *t = r; unsigned i; static const char hex[] = "0123456789abcdef"; - t = r = g_new(char, size > 0 ? size*3 : 1); - + assert(r); + assert(l > 0); + assert(mac); + if (size <= 0) { *r = 0; return r; } for (i = 0; i < size; i++) { + if (l < 3) + break; + *(t++) = hex[*mac >> 4]; *(t++) = hex[*mac & 0xF]; *(t++) = ':'; + l -= 3; + mac++; } - *(--t) = 0; + if (t > r) + *(t-1) = 0; + else + *r = 0; + return r; } +char *avahi_strup(char *s) { + char *c; + assert(s); + + for (c = s; *c; c++) + *c = (char) toupper(*c); + + return s; +} + +char *avahi_strdown(char *s) { + char *c; + assert(s); + + for (c = s; *c; c++) + *c = (char) tolower(*c); + + return s; +}