1
0
mirror of https://github.com/openbsd/src.git synced 2026-04-24 14:14:37 +00:00

improve the "No changes need to be saved" check

Instead of checking for the BFCHG flag in buffsave(), bubble it up to
filesave(), which is the interactive function.  This avoids prompting
for a filepath for e.g. when attempting to save the *scratch* buffer.

The only other place where buffsave() is called, anycb in buffer.c is
already guarding for a set file name and the BFCHG flag.

Initial diff from Han Boetes (hboetes at gmail), tweaked by me.
This commit is contained in:
op
2026-03-03 15:17:29 +00:00
parent 39a1044ba5
commit 5e9cb26331

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: file.c,v 1.104 2024/04/23 13:34:50 jsg Exp $ */
/* $OpenBSD: file.c,v 1.105 2026/03/03 15:17:29 op Exp $ */
/* This file is in the public domain. */
@@ -565,6 +565,11 @@ static int makebackup = TRUE;
int
filesave(int f, int n)
{
if ((curbp->b_flag & BFCHG) == 0) {
ewprintf("(No changes need to be saved)");
return (TRUE);
}
if (curbp->b_fname[0] == '\0')
return (filewrite(f, n));
else
@@ -572,8 +577,7 @@ filesave(int f, int n)
}
/*
* Save the contents of the buffer argument into its associated file. Do
* nothing if there have been no changes (is this a bug, or a feature?).
* Save the contents of the buffer argument into its associated file.
* Error if there is no remembered file name. If this is the first write
* since the read or visit, then a backup copy of the file is made.
* Allow user to select whether or not to make backup files by looking at
@@ -585,12 +589,6 @@ buffsave(struct buffer *bp)
int s;
FILE *ffp;
/* return, no changes */
if ((bp->b_flag & BFCHG) == 0) {
ewprintf("(No changes need to be saved)");
return (TRUE);
}
/* must have a name */
if (bp->b_fname[0] == '\0') {
dobeep();