tinyyarn

scenario testing of Unix command line tools
Log | Files | Refs | README | LICENSE

commit 40888ac024d6f1c6e669d219672446e9a4972043
parent 615e0b26c900a4afbe94daa8ec607786c0b3c34b
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Mon,  5 Apr 2021 13:09:36 +0100

path_exists: exit if stat == -1 and errno != ENOENT

Diffstat:
Mtyarn.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tyarn.c b/tyarn.c @@ -1,6 +1,6 @@ /* tyarn: minimal yarn implementation * - * Copyright © 2019 Richard Ipsum + * Copyright © 2019 - 2021 Richard Ipsum * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -97,8 +97,16 @@ static int tyarn_path_exists(lua_State *L) struct stat s; const char *path = luaL_checkstring(L, 1); - lua_pushboolean(L, (stat(path, &s) == -1 && errno == ENOENT) ? false : true); + if (stat(path, &s) == -1) { + if (errno != ENOENT) { + fprintf(stderr, "stat `%s': %s\n", path, strerror(errno)); + exit(1); + } + lua_pushboolean(L, false); /* ENOENT */ + return 1; + } + lua_pushboolean(L, true); return 1; }