Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net use fparseln() instead of fgetln() for consiste...



details:   https://anonhg.NetBSD.org/src/rev/6a186c042b73
branches:  trunk
changeset: 330054:6a186c042b73
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 19 15:09:07 2014 +0000

description:
use fparseln() instead of fgetln() for consistency (this was the last fgetln()
using parser in net/.
cVS: ----------------------------------------------------------------------

diffstat:

 lib/libc/net/ethers.c |  74 +++++++++++++++++++++++++-------------------------
 1 files changed, 37 insertions(+), 37 deletions(-)

diffs (159 lines):

diff -r 99d25ec97b50 -r 6a186c042b73 lib/libc/net/ethers.c
--- a/lib/libc/net/ethers.c     Thu Jun 19 15:08:18 2014 +0000
+++ b/lib/libc/net/ethers.c     Thu Jun 19 15:09:07 2014 +0000
@@ -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 @@
 {
        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 @@
        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 @@
                        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 @@
 {
        FILE *f;
        char *p;
-       size_t len;
        char try[MAXHOSTNAMELEN + 1];
 #ifdef YP
        int hostlen = (int)strlen(hostname);
@@ -153,16 +151,17 @@
        _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 @@
                        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



Home | Main Index | Thread Index | Old Index