From 34684c50a88034a63d96b0b8f54c590094fdca6f Mon Sep 17 00:00:00 2001 From: Jean-Francois Brousseau Date: Wed, 9 Mar 2005 16:20:49 +0000 Subject: fix mg's behaviour with regards to files on which we do not have write access. diff originally from vincent@ and forgotten for a while. ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@ --- usr.bin/mg/file.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'usr.bin/mg/file.c') diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 6043f47f195..755a0980c9f 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.29 2004/07/22 01:25:25 vincent Exp $ */ +/* $OpenBSD: file.c,v 1.30 2005/03/09 16:20:48 jfb Exp $ */ /* * File commands. @@ -54,8 +54,13 @@ filevisit(int f, int n) curbp = bp; if (showbuffer(bp, curwp, WFHARD) != TRUE) return FALSE; - if (bp->b_fname[0] == 0) - return readin(adjf); + if (bp->b_fname[0] == 0) { + int status; + + if ((status = readin(adjf)) != TRUE) + killbuffer(bp); + return status; + } return TRUE; } @@ -96,8 +101,13 @@ poptofile(int f, int n) return FALSE; curbp = bp; curwp = wp; - if (bp->b_fname[0] == 0) - return readin(adjf); + if (bp->b_fname[0] == 0) { + int status; + + if ((status = readin(adjf)) != TRUE) + killbuffer(bp); + return status; + } return TRUE; } @@ -140,7 +150,10 @@ readin(char *fname) /* might be old */ if (bclear(curbp) != TRUE) return TRUE; - status = insertfile(fname, fname, TRUE); + if ((status = insertfile(fname, fname, TRUE)) != TRUE) { + ewprintf("File is not readable: %s", fname); + return FALSE; + } /* * Call auto-executing function if we need to. -- cgit v1.2.3