Mercurial > hg > dhcpcd
changeset 259:b5103bcaa6ad draft
Stop using asprintf as it's not portable.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 07 Jan 2008 20:52:49 +0000 |
| parents | 21f18fa1dd56 |
| children | 0ae8f6f2a27d |
| files | configure.c |
| diffstat | 1 files changed, 27 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.c Mon Jan 07 20:49:25 2008 +0000 +++ b/configure.c Mon Jan 07 20:52:49 2008 +0000 @@ -25,10 +25,6 @@ * SUCH DAMAGE. */ -#ifdef __linux__ -# define _GNU_SOURCE /* for asprinf */ -#endif - #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -155,8 +151,10 @@ #ifdef ENABLE_RESOLVCONF char *resolvconf = NULL; - if (file_in_path ("resolvconf") == 0) { - asprintf (&resolvconf, "resolvconf -a %s", ifname); + if (file_in_path ("resolvconf") == 0) { + size_t len = strlen ("resolvconf -a ") + strlen (ifname) + 1; + resolvconf = xmalloc (sizeof (char) * len); + snprintf (resolvconf, len, "resolvconf -a %s", ifname); if ((f = popen (resolvconf , "w"))) logger (LOG_DEBUG, "sending DNS information to resolvconf"); else if (errno == EEXIST) @@ -395,6 +393,10 @@ #ifdef ENABLE_IPV4LL bool haslinklocal = false; #endif +#ifdef THERE_IS_NO_FORK + size_t skiplen; + char *skipp; +#endif if (! options || ! iface || ! dhcp) return (-1); @@ -504,7 +506,11 @@ #ifdef THERE_IS_NO_FORK free (dhcpcd_skiproutes); - dhcpcd_skiproutes = NULL; + /* We can never have more than 255 routes. So we need space + * for 255 3 digit numbers and commas */ + skiplen = 255 * 4 + 1; + skipp = dhcpcd_skiproutes = xmalloc (sizeof (char) * skiplen); + *skipp = '\0'; #endif /* Remember added routes */ @@ -558,20 +564,26 @@ /* If we have daemonised yet we need to record which routes * we failed to add so we can skip them */ else if (! options->daemonised) { - if (dhcpcd_skiproutes) { - char *p = NULL; - asprintf (&p, "%s,%d", dhcpcd_skiproutes, skip); - free (dhcpcd_skiproutes); - dhcpcd_skiproutes = p; - } else { - asprintf (&dhcpcd_skiproutes, "%d", skip); - } + /* We can never have more than 255 / 4 routes, so 3 chars is + * plently */ + if (*skipp) + *skipp++ = ','; + skipp += snprintf (skipp, dhcpcd_skiproutes + skiplen - skipp, + "%d", skip); } skip++; #endif } + } +#ifdef THERE_IS_NO_FORK + if (*dhcpcd_skiproutes) + *skipp = '\0'; + else { + free (dhcpcd_skiproutes); + dhcpcd_skiproutes = NULL; } +#endif #ifdef ENABLE_IPV4LL /* Ensure we always add the link local route if we got a private
