X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Falternative.c;h=436a0d47b2f1e3a3899afa308299c2cf6b33a47e;hb=8782ae678cf60713b5513016f16b039251c40870;hp=c9a0f48ac73a7c04fa245dbeceda6a73de35a6c2;hpb=c5544522f6409095627dc3d1129560195ab4ec40;p=catta diff --git a/avahi-common/alternative.c b/avahi-common/alternative.c index c9a0f48..436a0d4 100644 --- a/avahi-common/alternative.c +++ b/avahi-common/alternative.c @@ -26,39 +26,46 @@ #include #include #include +#include #include "alternative.h" +#include "malloc.h" -gchar * avahi_alternative_host_name(const gchar *s) { - const gchar *p, *e = NULL; - gchar *c, *r; - gint n; +char * avahi_alternative_host_name(const char *s) { + const char *p, *e; + char *r; - g_assert(s); + assert(s); + + e = s; for (p = s; *p; p++) if (!isdigit(*p)) e = p+1; - if (e && *e) - n = atoi(e)+1; - else - n = 2; + if (*e) { + char *c; + + if (!(c = avahi_strndup(s, e-s))) + return NULL; - c = e ? g_strndup(s, e-s) : g_strdup(s); - r = g_strdup_printf("%s%i", c, n); - g_free(c); + r = avahi_strdup_printf("%s%i", c, atoi(e)+1); + avahi_free(c); + + } else + r = avahi_strdup_printf("%s2", s); return r; - } -gchar *avahi_alternative_service_name(const gchar *s) { - const gchar *e; - g_assert(s); +char *avahi_alternative_service_name(const char *s) { + const char *e; + char *r; + + assert(s); if ((e = strstr(s, " #"))) { - const gchar *n, *p; + const char *n, *p; e += 2; while ((n = strstr(e, " #"))) @@ -72,10 +79,15 @@ gchar *avahi_alternative_service_name(const gchar *s) { } if (e) { - gchar *r, *c = g_strndup(s, e-s); - r = g_strdup_printf("%s%i", c, atoi(e)+1); - g_free(c); - return r; + char *c; + + if (!(c = avahi_strndup(s, e-s))) + return NULL; + + r = avahi_strdup_printf("%s%i", c, atoi(e)+1); + avahi_free(c); } else - return g_strdup_printf("%s #2", s); + r = avahi_strdup_printf("%s #2", s); + + return r; }