Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit Use fparseln to avoid newline hacks.



details:   https://anonhg.NetBSD.org/src/rev/96dede17171f
branches:  trunk
changeset: 343576:96dede17171f
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Feb 15 15:26:48 2016 +0000

description:
Use fparseln to avoid newline hacks.

diffstat:

 lib/libedit/history.c |  19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

diffs (62 lines):

diff -r 51f4fee68d8c -r 96dede17171f lib/libedit/history.c
--- a/lib/libedit/history.c     Mon Feb 15 15:18:01 2016 +0000
+++ b/lib/libedit/history.c     Mon Feb 15 15:26:48 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $    */
+/*     $NetBSD: history.c,v 1.48 2016/02/15 15:26:48 christos Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)history.c  8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.48 2016/02/15 15:26:48 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -743,7 +743,7 @@
        if ((fp = fopen(fname, "r")) == NULL)
                return i;
 
-       if ((line = fgetln(fp, &sz)) == NULL)
+       if ((line = fparseln(fp, &sz, NULL, NULL, 0)) == NULL)
                goto done;
 
        if (strncmp(line, hist_cookie, sz) != 0)
@@ -752,14 +752,8 @@
        ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
        if (ptr == NULL)
                goto done;
-       for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
-               char c = line[sz];
-
-               if (sz != 0 && line[sz - 1] == '\n')
-                       line[--sz] = '\0';
-               else
-                       line[sz] = '\0';
-
+       free(line);
+       for (i = 0; (line = fparseln(fp, &sz, NULL, NULL, 0)) != NULL; i++) {
                if (max_size < sz) {
                        char *nptr;
                        max_size = (sz + 1024) & (size_t)~1023;
@@ -771,15 +765,16 @@
                        ptr = nptr;
                }
                (void) strunvis(ptr, line);
-               line[sz] = c;
                if (HENTER(h, &ev, ct_decode_string(ptr, &conv)) == -1) {
                        i = -1;
                        goto oomem;
                }
+               free(line);
        }
 oomem:
        h_free(ptr);
 done:
+       free(line);
        (void) fclose(fp);
        return i;
 }



Home | Main Index | Thread Index | Old Index