summaryrefslogtreecommitdiff
path: root/usr.bin/mg/file.c
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-03-09 16:20:49 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-03-09 16:20:49 +0000
commit34684c50a88034a63d96b0b8f54c590094fdca6f (patch)
treec381c1c4c09f76b66de332fdb0243d1df4bdff9c /usr.bin/mg/file.c
parent51e684432edb921bd1a5233896eb5be1c3cdcdbb (diff)
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@
Diffstat (limited to 'usr.bin/mg/file.c')
-rw-r--r--usr.bin/mg/file.c25
1 files changed, 19 insertions, 6 deletions
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.