~richardipsum/tinyyarn

40888ac024d6f1c6e669d219672446e9a4972043 — Richard Ipsum 2 years ago 615e0b2
path_exists: exit if stat == -1 and errno != ENOENT
1 files changed, 10 insertions(+), 2 deletions(-)

M tyarn.c
M tyarn.c => tyarn.c +10 -2
@@ 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;
}