Date: Sun, 13 Jan 2013 21:28:47 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r245387 - head/lib/libutil Message-ID: <201301132128.r0DLSlnw099714@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Sun Jan 13 21:28:47 2013 New Revision: 245387 URL: http://svnweb.freebsd.org/changeset/base/245387 Log: libutil: utilize strsep instead of strcat in a loop in gr_make Submitted by: Christoph Mallon <christoph.mallon gmx.de> Modified: head/lib/libutil/gr_util.c Modified: head/lib/libutil/gr_util.c ============================================================================== --- head/lib/libutil/gr_util.c Sun Jan 13 21:26:57 2013 (r245386) +++ head/lib/libutil/gr_util.c Sun Jan 13 21:28:47 2013 (r245387) @@ -390,7 +390,9 @@ char * gr_make(const struct group *gr) { const char *group_line_format = "%s:%s:%ju:"; + const char *sep; char *line; + char *p; size_t line_size; int ndx; @@ -405,16 +407,18 @@ gr_make(const struct group *gr) } /* Create the group line and fill it. */ - if ((line = malloc(line_size)) == NULL) + if ((line = p = malloc(line_size)) == NULL) return (NULL); - snprintf(line, line_size, group_line_format, gr->gr_name, gr->gr_passwd, + p += sprintf(p, group_line_format, gr->gr_name, gr->gr_passwd, (uintmax_t)gr->gr_gid); - if (gr->gr_mem != NULL) + if (gr->gr_mem != NULL) { + sep = ""; for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++) { - strcat(line, gr->gr_mem[ndx]); - if (gr->gr_mem[ndx + 1] != NULL) - strcat(line, ","); + p = stpcpy(p, sep); + p = stpcpy(p, gr->gr_mem[ndx]); + sep = ","; } + } return (line); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301132128.r0DLSlnw099714>