diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2019-06-22 10:21:58 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2019-06-22 10:21:58 +0000 |
commit | 7a4e01b972d6e125bf13cc7520161bf4857bbffc (patch) | |
tree | 64c5be52e6078e1550c2b77cc19192ecd2c6718c /usr.bin/mg/file.c | |
parent | 68c0ff6cb2bc1917e5a61889e4a930010920fc4a (diff) |
This diff moves the check for a newline at the end of a buffer (when
saving it) earlier. This means data doesn't 'disappear' from the file
on disk while the user answers 'yes' or 'no'.
Diffstat (limited to 'usr.bin/mg/file.c')
-rw-r--r-- | usr.bin/mg/file.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 6483b6b5c8f..11fb2948d2c 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -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 @@ makebkfile(int f, int n) 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 @@ writeout(FILE ** ffp, struct buffer *bp, char *fn) 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); |