Re: git: c2caf3b3313f - main - flua: lposix: add more useful functions for general purpose scripts
Date: Mon, 30 Sep 2024 19:48:22 UTC
.. i have zero idea (and only look at time), but .. Kyle Evans wrote in <202409300353.48U3rZM7000710@gitrepo.freebsd.org>: |commit c2caf3b3313fe73bfc9b4b984c21da8d571f8798 |Author: Kyle Evans <kevans@FreeBSD.org> |AuthorDate: 2023-03-11 06:03:02 +0000 |Commit: Kyle Evans <kevans@FreeBSD.org> |CommitDate: 2024-09-30 03:52:20 +0000 | | flua: lposix: add more useful functions for general purpose scripts ... |+static int |+lua_read(lua_State *L) |+{ |+ char *buf; |+ ssize_t ret; |+ size_t sz; |+ int error, fd, narg; |+ |+ narg = lua_gettop(L); |+ luaL_argcheck(L, narg == 2, 1, |+ "read takes exactly two arguments (fd, size)"); |+ |+ fd = luaL_checkinteger(L, 1); |+ sz = luaL_checkinteger(L, 2); |+ |+ if (fd < 0) { |+ error = EBADF; |+ goto err; |+ } |+ |+ buf = malloc(sz); |+ if (buf == NULL) |+ goto err; |+ |+ /* |+ * For 0-byte reads, we'll still push the empty string and let the |+ * caller deal with EOF to match lposix semantics. |+ */ |+ ret = read(fd, buf, sz); |+ if (ret >= 0) |+ lua_pushlstring(L, buf, ret); |+ else if (ret < 0) |+ error = errno; /* Save to avoid clobber by free() */ |+ |+ free(buf); |+ if (error != 0) ^ uninit in ret>=0 case. ("Even clang should get it" (stupid me).) |+ goto err; |+ /* Just the string pushed. */ |+ return (1); |+err: ... --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)