jcs's openbsd hax
openbsd

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.

op 5e9cb263 39a1044b

+7 -9
+7 -9
usr.bin/mg/file.c
··· 1 - /* $OpenBSD: file.c,v 1.104 2024/04/23 13:34:50 jsg Exp $ */ 1 + /* $OpenBSD: file.c,v 1.105 2026/03/03 15:17:29 op Exp $ */ 2 2 3 3 /* This file is in the public domain. */ 4 4 ··· 565 565 int 566 566 filesave(int f, int n) 567 567 { 568 + if ((curbp->b_flag & BFCHG) == 0) { 569 + ewprintf("(No changes need to be saved)"); 570 + return (TRUE); 571 + } 572 + 568 573 if (curbp->b_fname[0] == '\0') 569 574 return (filewrite(f, n)); 570 575 else ··· 572 577 } 573 578 574 579 /* 575 - * Save the contents of the buffer argument into its associated file. Do 576 - * nothing if there have been no changes (is this a bug, or a feature?). 580 + * Save the contents of the buffer argument into its associated file. 577 581 * Error if there is no remembered file name. If this is the first write 578 582 * since the read or visit, then a backup copy of the file is made. 579 583 * Allow user to select whether or not to make backup files by looking at ··· 584 588 { 585 589 int s; 586 590 FILE *ffp; 587 - 588 - /* return, no changes */ 589 - if ((bp->b_flag & BFCHG) == 0) { 590 - ewprintf("(No changes need to be saved)"); 591 - return (TRUE); 592 - } 593 591 594 592 /* must have a name */ 595 593 if (bp->b_fname[0] == '\0') {