Module Name: src
Committed By: christos
Date: Thu Jun 19 15:09:07 UTC 2014
Modified Files:
src/lib/libc/net: ethers.c
Log Message:
use fparseln() instead of fgetln() for consistency (this was the last fgetln()
using parser in net/.
cVS: ----------------------------------------------------------------------
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/net/ethers.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/net/ethers.c
diff -u src/lib/libc/net/ethers.c:1.23 src/lib/libc/net/ethers.c:1.24
--- src/lib/libc/net/ethers.c:1.23 Tue Mar 20 13:44:18 2012
+++ src/lib/libc/net/ethers.c Thu Jun 19 11:09:07 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $ */
+/* $NetBSD: ethers.c,v 1.24 2014/06/19 15:09:07 christos Exp $ */
/*
* ethers(3N) a la Sun.
@@ -9,7 +9,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $");
+__RCSID("$NetBSD: ethers.c,v 1.24 2014/06/19 15:09:07 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -83,17 +83,14 @@ ether_ntohost(char *hostname, const stru
{
FILE *f;
char *p;
- size_t len;
struct ether_addr try;
-#ifdef YP
- char trybuf[sizeof "xx:xx:xx:xx:xx:xx"];
- int trylen;
-#endif
_DIAGASSERT(hostname != NULL);
_DIAGASSERT(e != NULL);
#ifdef YP
+ char trybuf[sizeof "xx:xx:xx:xx:xx:xx"];
+ int trylen;
trylen = snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
@@ -103,13 +100,14 @@ ether_ntohost(char *hostname, const stru
f = fopen(_PATH_ETHERS, "r");
if (f == NULL)
return -1;
- while ((p = fgetln(f, &len)) != NULL) {
- if (p[len - 1] != '\n')
- continue; /* skip lines w/o \n */
- p[--len] = '\0';
+ for (p = NULL;;) {
+ free(p);
+ p = fparseln(f, NULL, NULL, NULL, FPARSELN_UNESCALL);
+ if (p == NULL)
+ break;
#ifdef YP
/* A + in the file means try YP now. */
- if (len == 1 && *p == '+') {
+ if (strcmp(p, "+") == 0) {
char *ypbuf, *ypdom;
int ypbuflen;
@@ -118,24 +116,25 @@ ether_ntohost(char *hostname, const stru
if (yp_match(ypdom, "ethers.byaddr", trybuf,
trylen, &ypbuf, &ypbuflen))
continue;
- if (ether_line(ypbuf, &try, hostname) == 0) {
- free(ypbuf);
- (void)fclose(f);
- return 0;
- }
+ ypbuflen = ether_line(ypbuf, &try, hostname);
free(ypbuf);
+ if (ypbuflen == 0)
+ goto done;
continue;
}
#endif
if (ether_line(p, &try, hostname) == 0 &&
- memcmp(&try, e, sizeof try) == 0) {
- (void)fclose(f);
- return 0;
- }
+ memcmp(&try, e, sizeof try) == 0)
+ goto done;
}
+ free(p);
(void)fclose(f);
errno = ENOENT;
return -1;
+done:
+ free(p);
+ (void)fclose(f);
+ return 0;
}
int
@@ -143,7 +142,6 @@ ether_hostton(const char *hostname, stru
{
FILE *f;
char *p;
- size_t len;
char try[MAXHOSTNAMELEN + 1];
#ifdef YP
int hostlen = (int)strlen(hostname);
@@ -153,16 +151,17 @@ ether_hostton(const char *hostname, stru
_DIAGASSERT(e != NULL);
f = fopen(_PATH_ETHERS, "r");
- if (f==NULL)
+ if (f == NULL)
return -1;
- while ((p = fgetln(f, &len)) != NULL) {
- if (p[len - 1] != '\n')
- continue; /* skip lines w/o \n */
- p[--len] = '\0';
+ for (p = NULL;;) {
+ free(p);
+ p = fparseln(f, NULL, NULL, NULL, FPARSELN_UNESCALL);
+ if (p == NULL)
+ break;
#ifdef YP
/* A + in the file means try YP now. */
- if (len == 1 && *p == '+') {
+ if (strcmp(p, "+") == 0) {
char *ypbuf, *ypdom;
int ypbuflen;
@@ -171,23 +170,24 @@ ether_hostton(const char *hostname, stru
if (yp_match(ypdom, "ethers.byname", hostname, hostlen,
&ypbuf, &ypbuflen))
continue;
- if (ether_line(ypbuf, e, try) == 0) {
- free(ypbuf);
- (void)fclose(f);
- return 0;
- }
+ ypbuflen = ether_line(ypbuf, e, try);
free(ypbuf);
+ if (ypbuflen == 0)
+ goto done;
continue;
}
#endif
- if (ether_line(p, e, try) == 0 && strcmp(hostname, try) == 0) {
- (void)fclose(f);
- return 0;
- }
+ if (ether_line(p, e, try) == 0 && strcmp(hostname, try) == 0)
+ goto done;
}
+ free(p);
(void)fclose(f);
errno = ENOENT;
return -1;
+done:
+ free(p);
+ (void)fclose(f);
+ return 0;
}
int