diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-24 21:13:46 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-24 21:13:46 +0000 |
commit | 89394212b6cf9fa13711a2cf91e4d5c307aeb8c2 (patch) | |
tree | b23ba33fdcd8817b2e920fee8f787627146677e1 /usr.bin/dc/dc.c | |
parent | d572705eefb36ad471cccb729541c936e90b5e95 (diff) |
For those of us (including me) who can't type: show an error message if
the argument is a dir. ok tom@
commit #1000 in slighlty less than 1000 days of commit access :-)
Diffstat (limited to 'usr.bin/dc/dc.c')
-rw-r--r-- | usr.bin/dc/dc.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/dc/dc.c b/usr.bin/dc/dc.c index 7f249a8576a..6805a23e183 100644 --- a/usr.bin/dc/dc.c +++ b/usr.bin/dc/dc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dc.c,v 1.7 2006/01/15 19:11:59 otto Exp $ */ +/* $OpenBSD: dc.c,v 1.8 2006/03/24 21:13:45 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -17,10 +17,12 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: dc.c,v 1.7 2006/01/15 19:11:59 otto Exp $"; +static const char rcsid[] = "$OpenBSD: dc.c,v 1.8 2006/03/24 21:13:45 otto Exp $"; #endif /* not lint */ +#include <sys/stat.h> #include <err.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -46,6 +48,8 @@ main(int argc, char *argv[]) FILE *file; struct source src; char *buf, *p; + struct stat st; + if ((buf = strdup("")) == NULL) err(1, NULL); @@ -85,6 +89,13 @@ main(int argc, char *argv[]) return (0); } if (argc == 1) { + if (stat(argv[0], &st) == -1) + err(1, "%s", argv[0]); + if (S_ISDIR(st.st_mode)) { + errno = EISDIR; + err(1, "%s", argv[0]); + } + file = fopen(argv[0], "r"); if (file == NULL) err(1, "cannot open file %s", argv[0]); |