harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit ffa76a947a38952f158e8eae53555c328305232b
parent 49532206939646799ca3430ff1d13484c62b2d2b
Author: Pierre Curto <pierre.curto@gmail.com>
Date:   Mon, 14 Nov 2022 17:01:58 +0100

harec: provide error when run on a directory

Fixes: https://todo.sr.ht/~sircmpwn/hare/770

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

Diffstat:
Msrc/main.c | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <unistd.h> #include "ast.h" #include "check.h" @@ -154,6 +155,13 @@ main(int argc, char *argv[]) in = stdin; } else { in = fopen(path, "r"); + struct stat buf; + if (in && fstat(fileno(in), &buf) == 0 + && S_ISDIR(buf.st_mode) != 0) { + fprintf(stderr, "Unable to open %s for reading: Is a directory\n", + path); + return EXIT_FAILURE; + } } if (!in) {