Date: Fri, 21 Apr 2006 19:20:29 GMT From: Todd Miller <millert@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 95818 for review Message-ID: <200604211920.k3LJKTXH025530@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95818 Change 95818 by millert@millert_g5tower on 2006/04/21 19:19:35 Improve readability Affected files ... .. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/libsecompat/getline.c#2 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/libsecompat/getline.c#2 (text+ko) ==== @@ -37,24 +37,25 @@ * Note that outsize is not changed unless memory is allocated. */ ssize_t -getline(char **outbuf, size_t *outsize, FILE *fp) +getline(char **bufp, size_t *bufsizep, FILE *fp) { - char *buf; - size_t len; + char *line, *buf = *bufp; + size_t linelen, bufsize = *bufsizep; - buf = fgetln(fp, &len); - if (buf == NULL) + line = fgetln(fp, &linelen); + if (line == NULL) return (-1); /* Assumes realloc() accepts NULL for ptr (C99) */ - if (*outbuf == NULL || *outsize < len + 1) { - void *tmp = realloc(*outbuf, len + 1); - if (tmp == NULL) + if (buf == NULL || bufsize < linelen + 1) { + bufsize = linelen + 1; + buf = realloc(buf, bufsize); + if (buf == NULL) return (-1); - *outbuf = tmp; - *outsize = len + 1; + *bufp = buf; + *bufsizep = bufsize; } - memcpy(*outbuf, buf, len); - (*outbuf)[len] = '\0'; - return (len); + memcpy(buf, line, linelen); + buf[linelen] = '\0'; + return (linelen); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604211920.k3LJKTXH025530>