mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
Add error reporting to redbean Slurp (#268)
This should allow `content = assert(Slurp(filename))` to work as expected and report an error if file doesn't exist or can't be read.
This commit is contained in:
parent
44c87b83ff
commit
1eed7d47bd
1 changed files with 11 additions and 5 deletions
|
@ -4639,12 +4639,18 @@ static int LuaEncodeLatin1(lua_State *L) {
|
|||
}
|
||||
|
||||
static int LuaSlurp(lua_State *L) {
|
||||
char *p;
|
||||
char *p, *f;
|
||||
size_t n;
|
||||
p = xslurp(luaL_checkstring(L, 1), &n);
|
||||
lua_pushlstring(L, p, n);
|
||||
free(p);
|
||||
return 1;
|
||||
f = luaL_checkstring(L, 1);
|
||||
if ((p = xslurp(f, &n))) {
|
||||
lua_pushlstring(L, p, n);
|
||||
free(p);
|
||||
return 1;
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, gc(xasprintf("Can't slurp file %`'s: %m", f)));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
static int LuaIndentLines(lua_State *L) {
|
||||
|
|
Loading…
Reference in a new issue