=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/file.c,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- src/usr.bin/mg/file.c 2016/01/02 10:39:19 1.100 +++ src/usr.bin/mg/file.c 2019/06/22 10:21:57 1.101 @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.100 2016/01/02 10:39:19 lum Exp $ */ +/* $OpenBSD: file.c,v 1.101 2019/06/22 10:21:57 lum Exp $ */ /* This file is in the public domain. */ @@ -668,9 +668,10 @@ int writeout(FILE ** ffp, struct buffer *bp, char *fn) { - struct stat statbuf; - int s; - char dp[NFILEN]; + struct stat statbuf; + struct line *lpend; + int s, eobnl; + char dp[NFILEN]; if (stat(fn, &statbuf) == -1 && errno == ENOENT) { errno = 0; @@ -686,10 +687,16 @@ return (FIOERR); } } + lpend = bp->b_headp; + eobnl = 0; + if (llength(lback(lpend)) != 0) { + if (eyorn("No newline at end of file, add one") == TRUE) + eobnl = 1; + } /* open writes message */ if ((s = ffwopen(ffp, fn, bp)) != FIOSUC) return (FALSE); - s = ffputbuf(*ffp, bp); + s = ffputbuf(*ffp, bp, eobnl); if (s == FIOSUC) { /* no write error */ s = ffclose(*ffp, bp);