diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-10-13 20:23:02 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-10-13 20:23:02 +0000 |
commit | a72ced90ddf0930ee6a27432516e5a882800a30e (patch) | |
tree | 91ed5e3816c16b85e2e9eabd9f55c1ad6dc6e8e7 /usr.bin | |
parent | 6a60c6908c6c48c32478ac4d20d9522a09c3027e (diff) |
Make dired buffer read-only by default.
Noticed by Han Boetes
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/def.h | 3 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 18 | ||||
-rw-r--r-- | usr.bin/mg/fileio.c | 22 |
3 files changed, 36 insertions, 7 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 8157b455150..724fe4dac4b 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.69 2005/10/13 19:46:45 kjell Exp $ */ +/* $OpenBSD: def.h,v 1.70 2005/10/13 20:23:01 kjell Exp $ */ /* This file is in the public domain. */ @@ -429,6 +429,7 @@ int copy(char *, char *); BUFFER *dired_(char *); int d_makename(LINE *, char *, int); LIST *make_file_list(char *); +int fisdir(const char *); /* kbd.c X */ int do_meta(int, int); diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 784e36ec370..fbae3a2dac9 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.40 2005/10/13 19:46:45 kjell Exp $ */ +/* $OpenBSD: file.c,v 1.41 2005/10/13 20:23:01 kjell Exp $ */ /* This file is in the public domain. */ @@ -6,9 +6,10 @@ * File commands. */ -#include <libgen.h> #include "def.h" +#include <libgen.h> + /* * Insert a file into the current buffer. Real easy - just call the * insertfile routine with the file name. @@ -205,7 +206,7 @@ int readin(char *fname) { MGWIN *wp; - int status, i; + int status, i, ro = FALSE; PF *ael; /* might be old */ @@ -236,8 +237,17 @@ readin(char *fname) } } - /* We need to set the READONLY flag after we insert the file. */ + /* + * We need to set the READONLY flag after we insert the file, + * unless the file is a directory. + */ if (access(fname, W_OK) && errno != ENOENT) + ro = TRUE; +#ifndef NO_DIRED + if (fisdir(fname) == TRUE) + ro = TRUE; +#endif + if (ro == TRUE) curbp->b_flag |= BFREADONLY; else curbp->b_flag &=~ BFREADONLY; diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index edb8e5af089..8e36eaf759d 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.53 2005/10/13 19:46:45 kjell Exp $ */ +/* $OpenBSD: fileio.c,v 1.54 2005/10/13 20:23:01 kjell Exp $ */ /* This file is in the public domain. */ @@ -38,7 +38,7 @@ ffropen(const char *fn, BUFFER *bp) } /* If 'fn' is a directory open it with dired. */ - if ((stat(fn, &statbuf) == 0) && S_ISDIR(statbuf.st_mode)) + if (fisdir(fn) == TRUE) #ifdef NO_DIRED return (FIOERR); #else @@ -621,3 +621,21 @@ make_file_list(char *buf) return (last); } + +/* + * Test if a supplied filename refers to a directory + * Returns ABORT on error, TRUE if directory. FALSE otherwise + */ +int +fisdir(const char *fname) +{ + struct stat statbuf; + + if (stat(fname, &statbuf) != 0) + return (ABORT); + + if (S_ISDIR(statbuf.st_mode)) + return (TRUE); + + return (FALSE); +} |