static int Paug_load(lua_State *L) { augeas *a = Paug_checkarg(L, 1); return pushresult(L, aug_load(a), a, NULL); }
static int f_flush (lua_State *L) { return pushresult(L, fflush(tofile(L)) == 0, NULL); }
static void io_rename (void) { pushresult(rename(luaL_check_string(1), luaL_check_string(2)) == 0); }
/* ** function to close 'popen' files */ static int io_pclose (lua_State *L) { FILE **p = tofilep(L); int ok = lua_pclose(L, *p); *p = NULL; return pushresult(L, ok, NULL); }
static int io_tmpfile (lua_State *L) { FILE **pf = newfile(L); *pf = tmpfile(); return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; }
static int io_remove (lua_State *L) { const char *filename = luaL_checkstring(L, 1); SAFE_CHECK_FILE_DATA(L, 1); return pushresult(L, remove(filename) == 0, filename); }
static int io_rename (lua_State *L) { return pushresult(L, rename(luaL_check_string(L, 1), luaL_check_string(L, 2)) == 0); }
static int Pwait(lua_State *L) /** wait([pid]) */ { pid_t pid = luaL_optint(L, 1, -1); return pushresult(L, waitpid(pid, NULL, 0), NULL); }
static int Psetgid(lua_State *L) /** setgid(name or id) */ { return pushresult(L, setgid(mygetgid(L, 1)), NULL); }
/* ** function to close 'popen' files */ static int pipe_close (lua_State *L) { FILE **p = tofilep(L); int ok = fclose(*p); *p = NULL; return pushresult(L, ok, NULL); }
static int Psymlink(lua_State *L) /** symlink(oldpath,newpath) */ { const char *oldpath = luaL_checkstring(L, 1); const char *newpath = luaL_checkstring(L, 2); return pushresult(L, symlink(oldpath, newpath), NULL); }
/*** Fork this program. @function fork @treturn[1] int `0` in the resulting child process @treturn[2] int process id of child, in the calling process @return[3] nil @treturn[3] string error message @treturn[3] int errnum @see fork(2) @see fork.lua @see fork2.lua @usage local unistd = require "posix.unistd" local pid, errmsg = unistd.fork () if pid == nil then error (errmsg) elseif pid == 0 then print ("in child:", unistd.getpid "pid") else print (require "posix.sys.wait".wait (pid)) end os.exit () */ static int Pfork(lua_State *L) { checknargs(L, 0); return pushresult(L, fork(), NULL); }
/*** Get id of foreground process group of terminal *fd*. @function tcgetpgrp @int fd the file descriptor of the controlling terminal of the current process @treturn[1] int id of foreground process group @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see tcgetpgrp(2) */ static int Ptcgetpgrp(lua_State *L) { int fd = checkint(L, 1); return pushresult(L, tcgetpgrp(fd), NULL); }
/*** Get a message queue identifier @function msgget @int key message queue id, or `IPC_PRIVATE` for a new queue @int[opt=0] flags bitwise OR of zero or more from `IPC_CREAT` and `IPC_EXCL`, and access permissions `S_IRUSR`, `S_IWUSR`, `S_IRGRP`, `S_IWGRP`, `S_IROTH` and `S_IWOTH` (from @{posix.sys.stat}) @treturn[1] int message queue identifier, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see msgget(2) */ static int Pmsgget(lua_State *L) { checknargs (L, 2); return pushresult(L, msgget(checkint(L, 1), optint(L, 2, 0)), "msgget"); }
static int io_flush (lua_State *L) { SAFE_CHECK_FILE_MOD(L); return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); }
static int io_remove (lua_State *L) { const char *filename = luaL_checkstring(L, 1); // return pushresult(L, remove(filename) == 0, filename); return pushresult(L, 0, filename); }
static int f_flush (lua_State *L) { SAFE_CHECK_FILE_MOD(L); return pushresult(L, fflush(tofile(L, 1)) == 0, NULL); }
static int io_rename (lua_State *L) { const char *fromname = luaL_checkstring(L, 1); const char *toname = luaL_checkstring(L, 2); // return pushresult(L, rename(fromname, toname) == 0, fromname); return pushresult(L, 0, fromname); }
static int io_close (lua_State *L) { IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); lua_pop(L, 1); /* remove upvalue */ return pushresult(L, closefile(L, ctrl, getnonullfile(L, ctrl, 1))); }
static int Prmdir(lua_State *L) /** rmdir(path) */ { const char *path = luaL_checkstring(L, 1); return pushresult(L, rmdir(path), path); }
/*** Get and set options on sockets. @function setsockopt @int fd socket descriptor @int level one of `SOL_SOCKET`, `IPPROTO_IPV6`, `IPPROTO_TCP` @int name option name, varies according to `level` value @param value1 option value to set @param[opt] value2 some option *name*s need an additional value @treturn[1] int `0`, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see setsockopt(2) @usage ok, errmsg = P.setsockopt (sock, P.SOL_SOCKET, P.SO_SNDTIMEO, 1, 0) */ static int Psetsockopt(lua_State *L) { int fd = checkint(L, 1); int level = checkint(L, 2); int optname = checkint(L, 3); struct linger linger; struct timeval tv; struct ipv6_mreq mreq6; #ifdef SO_BINDTODEVICE struct ifreq ifr; #endif int vint = 0; void *val = NULL; socklen_t len = sizeof(vint); switch (level) { case SOL_SOCKET: switch (optname) { case SO_LINGER: checknargs(L, 5); linger.l_onoff = checkint(L, 4); linger.l_linger = checkint(L, 5); val = &linger; len = sizeof(linger); break; case SO_RCVTIMEO: case SO_SNDTIMEO: checknargs(L, 5); tv.tv_sec = checkint(L, 4); tv.tv_usec = checkint(L, 5); val = &tv; len = sizeof(tv); break; #ifdef SO_BINDTODEVICE case SO_BINDTODEVICE: checknargs(L, 4); strlcpy(ifr.ifr_name, luaL_checkstring(L, 4), IFNAMSIZ); val = 𝔦 len = sizeof(ifr); #endif default: checknargs(L, 4); break; } break; #if defined IPV6_JOIN_GROUP && defined IPV6_LEAVE_GROUP case IPPROTO_IPV6: switch (optname) { case IPV6_JOIN_GROUP: case IPV6_LEAVE_GROUP: checknargs(L, 4); memset(&mreq6, 0, sizeof mreq6); inet_pton(AF_INET6, luaL_checkstring(L, 4), &mreq6.ipv6mr_multiaddr); val = &mreq6; len = sizeof(mreq6); break; default: checknargs(L, 4); break; } break; #endif case IPPROTO_TCP: switch (optname) { default: checknargs(L, 4); break; } break; default: break; } /* Default fallback to int if no specific handling of type above */ if (val == NULL) { vint = checkint(L, 4); val = &vint; len = sizeof(vint); } return pushresult(L, setsockopt(fd, level, optname, val, len), "setsockopt"); }
static int Punlink(lua_State *L) /** unlink(path) */ { const char *path = luaL_checkstring(L, 1); return pushresult(L, unlink(path), path); }
/* ** function to close regular files */ static int io_fclose (lua_State *L) { FILE **p = tofilep(L); int ok = (fclose(*p) == 0); *p = NULL; return pushresult(L, ok, NULL); }
static int Pfileno(lua_State *L) /** fileno(filehandle) */ { FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE); return pushresult(L, fileno(f), NULL); }
static int io_flush (lua_State *L) { return pushresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); }
static int Pfork(lua_State *L) /** fork() */ { return pushresult(L, fork(), NULL); }
static void io_remove (void) { pushresult(remove(luaL_check_string(1)) == 0); }
static int Pkill(lua_State *L) /** kill(pid,[sig]) */ { pid_t pid = luaL_checkint(L, 1); int sig = luaL_optint(L, 2, SIGTERM); return pushresult(L, kill(pid, sig), NULL); }
static int Pmkdir(lua_State *L) /** mkdir(path) */ { const char *path = luaL_checkstring(L, 1); return pushresult(L, mkdir(path, 0777), path); }
static int Paug_matches(lua_State *L) { augeas *a = Paug_checkarg(L, 1); const char *path = luaL_checkstring(L, 2); return pushresult(L, aug_match(a, path, NULL), a, path); }