=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/fileio.c,v retrieving revision 1.105 retrieving revision 1.106 diff -u -r1.105 -r1.106 --- src/usr.bin/mg/fileio.c 2018/04/13 14:11:37 1.105 +++ src/usr.bin/mg/fileio.c 2019/06/22 10:21:57 1.106 @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.105 2018/04/13 14:11:37 florian Exp $ */ +/* $OpenBSD: fileio.c,v 1.106 2019/06/22 10:21:57 lum Exp $ */ /* This file is in the public domain. */ @@ -150,11 +150,12 @@ * buffer. Return the status. */ int -ffputbuf(FILE *ffp, struct buffer *bp) +ffputbuf(FILE *ffp, struct buffer *bp, int eobnl) { - struct line *lp, *lpend; + struct line *lp, *lpend; lpend = bp->b_headp; + for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) { if (fwrite(ltext(lp), 1, llength(lp), ffp) != llength(lp)) { dobeep(); @@ -164,14 +165,9 @@ if (lforw(lp) != lpend) /* no implied \n on last line */ putc('\n', ffp); } - /* - * XXX should be variable controlled (once we have variables) - */ - if (llength(lback(lpend)) != 0) { - if (eyorn("No newline at end of file, add one") == TRUE) { - lnewline_at(lback(lpend), llength(lback(lpend))); - putc('\n', ffp); - } + if (eobnl) { + lnewline_at(lback(lpend), llength(lback(lpend))); + putc('\n', ffp); } return (FIOSUC); }