@see errno(3) @usage P.errno (P.EBADF) */ static int Pset_errno(lua_State *L) { errno = checkint(L, 1); checknargs(L, 1); return 0; } static const luaL_Reg posix_errno_fns[] = { LPOSIX_FUNC( Perrno ), LPOSIX_FUNC( Pset_errno ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Error constants. Any constants not available in the underlying system will be `nil` valued. If you find one of the luaposix APIs returns an error code not listed here,
@int[opt] mode new file creation mask @treturn int previous umask @see umask(2) @see posix.umask */ static int Pumask(lua_State *L) { checknargs(L, 1); return pushintresult(umask((mode_t) checkint(L, 1))); } static const luaL_Reg posix_sys_stat_fns[] = { LPOSIX_FUNC( PS_ISBLK ), LPOSIX_FUNC( PS_ISCHR ), LPOSIX_FUNC( PS_ISDIR ), LPOSIX_FUNC( PS_ISFIFO ), LPOSIX_FUNC( PS_ISLNK ), LPOSIX_FUNC( PS_ISREG ), LPOSIX_FUNC( PS_ISSOCK ), LPOSIX_FUNC( Pchmod ), LPOSIX_FUNC( Plstat ), LPOSIX_FUNC( Pmkdir ), LPOSIX_FUNC( Pmkfifo ), LPOSIX_FUNC( Pstat ), LPOSIX_FUNC( Pumask ), {NULL, NULL} };
lua_pushstring(L, "SIG_DFL"); else if (oldsa.sa_handler == SIG_IGN) lua_pushstring(L, "SIG_IGN"); else { lua_pushinteger(L, sig); lua_pushlightuserdata(L, oldsa.sa_handler); lua_pushcclosure(L, sig_handler_wrap, 2); } return 1; } static const luaL_Reg posix_signal_fns[] = { LPOSIX_FUNC( Pkill ), LPOSIX_FUNC( Pkillpg ), LPOSIX_FUNC( Praise ), LPOSIX_FUNC( Psignal ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Signal constants. Any constants not available in the underlying system will be `nil` valued.
Psched_setscheduler(lua_State *L) { struct sched_param sched_param = {0}; pid_t pid = optint(L, 1, 0); int policy = optint(L, 2, SCHED_OTHER); sched_param.sched_priority = optint (L, 3, 0); checknargs(L, 3); return pushresult(L, sched_setscheduler(pid, policy, &sched_param), NULL); } #endif static const luaL_Reg posix_sched_fns[] = { #if HAVE_SCHED_GETSCHEDULER LPOSIX_FUNC( Psched_getscheduler ), #endif #if HAVE_SCHED_SETSCHEDULER LPOSIX_FUNC( Psched_setscheduler ), #endif {NULL, NULL} }; /*** Constants. @section constants */ /*** Scheduler constants.
@treturn[2] int errnum @see uname(2) */ static int Puname(lua_State *L) { struct utsname u; checknargs(L, 0); if (uname(&u)==-1) return pusherror(L, "uname"); return pushutsname(L, &u); } static const luaL_Reg posix_sys_utsname_fns[] = { LPOSIX_FUNC( Puname ), {NULL, NULL} }; LUALIB_API int luaopen_posix_sys_utsname(lua_State *L) { luaL_newlib(L, posix_sys_utsname_fns); lua_pushstring(L, LPOSIX_VERSION_STRING("sys.utsname")); lua_setfield(L, -2, "version"); return 1; }
Rewind next @{getpwent} back to start of database. @function setpwent @see getpwent */ static int Psetpwent(lua_State *L) { checknargs(L, 0); setpwent(); return 0; } static const luaL_Reg posix_pwd_fns[] = { LPOSIX_FUNC( Pendpwent ), LPOSIX_FUNC( Pgetpwent ), LPOSIX_FUNC( Pgetpwnam ), LPOSIX_FUNC( Pgetpwuid ), LPOSIX_FUNC( Psetpwent ), {NULL, NULL} }; int luaopen_posix_pwd(lua_State *L) { luaL_register(L, "posix.pwd", posix_pwd_fns); lua_pushliteral(L, "posix.pwd for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version");
Rewind next @{getgrent} back to start of database. @function setgrent @see getgrent */ static int Psetgrent(lua_State *L) { checknargs(L, 0); setgrent(); return 0; } static const luaL_Reg posix_grp_fns[] = { LPOSIX_FUNC( Pendgrent ), LPOSIX_FUNC( Pgetgrent ), LPOSIX_FUNC( Pgetgrgid ), LPOSIX_FUNC( Pgetgrnam ), LPOSIX_FUNC( Psetgrent ), {NULL, NULL} }; int luaopen_posix_grp(lua_State *L) { luaL_register(L, "posix.grp", posix_grp_fns); lua_pushliteral(L, "posix.grp for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version");
*/ static int Pstatvfs(lua_State *L) { struct statvfs s; const char *path = luaL_checkstring(L, 1); checknargs(L, 1); if (statvfs(path, &s) == -1) return pusherror(L, path); return pushstatvfs(L, &s); } static const luaL_Reg posix_sys_statvfs_fns[] = { LPOSIX_FUNC( Pstatvfs ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Statvfs constants. Any constants not available in the underlying system will be `nil` valued. @table posix.sys.statvfs @int ST_RDONLY read-only file system @int ST_NOSUID does not support `S_ISUID` nor `S_ISGID` file mode bits
unsigned int i; lua_newtable(L); for (i=1; i<=globres.gl_pathc; i++) { lua_pushstring(L, globres.gl_pathv[i-1]); lua_rawseti(L, -2, i); } globfree(&globres); return 1; } } static const luaL_Reg posix_glob_fns[] = { LPOSIX_FUNC( Pglob ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Glob constants. @table posix.glob @int GLOB_MARK append slashes to matches that are directories. @usage -- Print glob constants supported on this host.
if (val == NULL) { vint = checkint(L, 4); val = &vint; len = sizeof(vint); } return pushresult(L, setsockopt(fd, level, optname, val, len), "setsockopt"); } #endif static const luaL_Reg posix_sys_socket_fns[] = { #if _POSIX_VERSION >= 200112L LPOSIX_FUNC( Psocket ), LPOSIX_FUNC( Psocketpair ), LPOSIX_FUNC( Pgetaddrinfo ), LPOSIX_FUNC( Pconnect ), LPOSIX_FUNC( Pbind ), LPOSIX_FUNC( Plisten ), LPOSIX_FUNC( Paccept ), LPOSIX_FUNC( Precv ), LPOSIX_FUNC( Precvfrom ), LPOSIX_FUNC( Psend ), LPOSIX_FUNC( Psendto ), LPOSIX_FUNC( Pshutdown ), LPOSIX_FUNC( Psetsockopt ), #endif {NULL, NULL} };
Check for any printable character including space. @function isprint @string character to act on @treturn int non-zero if character is not in the class @see isprint(3) */ static int Pisprint(lua_State *L) { return bind_ctype(L, &isprint); } static const luaL_Reg posix_ctype_fns[] = { LPOSIX_FUNC( Pisgraph ), LPOSIX_FUNC( Pisprint ), {NULL, NULL} }; int luaopen_posix_ctype(lua_State *L) { luaL_register(L, "posix.ctype", posix_ctype_fns); lua_pushliteral(L, "posix.ctype for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version"); return 1; }
@see openpt @see ptsname @see grantpt */ static int Punlockpt(lua_State *L) { int fd=checkint(L, 1); checknargs(L, 1); return pushresult(L, unlockpt(fd), "unlockpt"); } static const luaL_Reg posix_stdlib_fns[] = { LPOSIX_FUNC( Pabort ), LPOSIX_FUNC( Pgetenv ), LPOSIX_FUNC( Pgrantpt ), LPOSIX_FUNC( Pmkdtemp ), LPOSIX_FUNC( Pmkstemp ), LPOSIX_FUNC( Popenpt ), LPOSIX_FUNC( Pptsname ), LPOSIX_FUNC( Prealpath ), LPOSIX_FUNC( Psetenv ), LPOSIX_FUNC( Punlockpt ), {NULL, NULL} }; LUALIB_API int luaopen_posix_stdlib(lua_State *L)
*/ static int Putime(lua_State *L) { struct utimbuf times; time_t currtime = time(NULL); const char *path = luaL_checkstring(L, 1); times.modtime = optint(L, 2, currtime); times.actime = optint(L, 3, currtime); checknargs(L, 3); return pushresult(L, utime(path, ×), path); } static const luaL_Reg posix_utime_fns[] = { LPOSIX_FUNC( Putime ), {NULL, NULL} }; LUALIB_API int luaopen_posix_utime(lua_State *L) { luaL_register(L, "posix.utime", posix_utime_fns); lua_pushstring(L, LPOSIX_VERSION_STRING("utime")); lua_setfield(L, -2, "version"); return 1; }
if (res != -1) { lua_pushinteger(L, msg->mtype); lua_pushlstring(L, msg->mtext, res - sizeof(long)); } lalloc(ud, msg, msgsz, 0); return (res == -1) ? pusherror(L, NULL) : 2; } #endif /*!HAVE_SYSV_MESSAGING*/ static const luaL_Reg posix_sys_msg_fns[] = { #if HAVE_SYSV_MESSAGING LPOSIX_FUNC( Pmsgget ), LPOSIX_FUNC( Pmsgsnd ), LPOSIX_FUNC( Pmsgrcv ), #endif {NULL, NULL} }; /*** Constants. @section constants */ /*** Message constants. Any constants not available in the underlying system will be `nil` valued.
@treturn[2] int errnum @see write(2) */ static int Pwrite(lua_State *L) { int fd = checkint(L, 1); const char *buf = luaL_checkstring(L, 2); checknargs(L, 2); return pushresult(L, write(fd, buf, lua_objlen(L, 2)), NULL); } static const luaL_Reg posix_unistd_fns[] = { LPOSIX_FUNC( P_exit ), LPOSIX_FUNC( Paccess ), LPOSIX_FUNC( Pchdir ), LPOSIX_FUNC( Pchown ), LPOSIX_FUNC( Pclose ), #if defined HAVE_CRYPT LPOSIX_FUNC( Pcrypt ), #endif LPOSIX_FUNC( Pdup ), LPOSIX_FUNC( Pdup2 ), LPOSIX_FUNC( Pexec ), LPOSIX_FUNC( Pexecp ), #if LPOSIX_2001_COMPLIANT LPOSIX_FUNC( Pfdatasync ), #endif LPOSIX_FUNC( Pfork ),
{ lua_pushcfunction(L, dir_gc); lua_setfield(L, -2, "__gc"); } lua_setmetatable(L, -2); *d = opendir(path); if (*d == NULL) return pusherror(L, path); lua_pushcclosure(L, aux_files, 1); return 1; } static const luaL_Reg posix_dirent_fns[] = { LPOSIX_FUNC( Pdir ), LPOSIX_FUNC( Pfiles ), {NULL, NULL} }; LUALIB_API int luaopen_posix_dirent(lua_State *L) { luaL_register(L, "posix.dirent", posix_dirent_fns); lua_pushliteral(L, "posix.dirent for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version"); return 1; }
local ok, errmsg = P.rename (oldpath, newpath) if not ok then error (errmsg) end */ static int Prename(lua_State *L) /** rename(oldpath, newpath) */ { const char *oldpath = luaL_checkstring(L, 1); const char *newpath = luaL_checkstring(L, 2); checknargs(L, 2); return pushresult(L, rename(oldpath, newpath), NULL); } static const luaL_Reg posix_stdio_fns[] = { LPOSIX_FUNC( Pctermid ), LPOSIX_FUNC( Pfileno ), LPOSIX_FUNC( Pfdopen ), LPOSIX_FUNC( Prename ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Stdio constants. Any constants not available in the underlying system will be `nil` valued.
const char *path = luaL_checklstring(L, 1, &len); size_t path_len; checknargs(L, 1); path_len = strlen(path) + 1; lalloc = lua_getallocf(L, &ud); if ((b = (char*)lalloc(ud, NULL, 0, path_len)) == NULL) return pusherror(L, "lalloc"); lua_pushstring(L, dirname(strcpy(b,path))); lalloc(ud, b, path_len, 0); return 1; } static const luaL_Reg posix_libgen_fns[] = { LPOSIX_FUNC( Pbasename ), LPOSIX_FUNC( Pdirname ), {NULL, NULL} }; int luaopen_posix_libgen(lua_State *L) { luaL_register(L, "posix.libgen", posix_libgen_fns); lua_pushliteral(L, "posix.libgen for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version"); return 1; }
lua_pushinteger(L, WTERMSIG(status)); return 3; } else if (WIFSTOPPED(status)) { lua_pushliteral(L,"stopped"); lua_pushinteger(L, WSTOPSIG(status)); return 3; } return 1; } static const luaL_Reg posix_sys_wait_fns[] = { LPOSIX_FUNC( Pwait ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Wait constants. Any constants not available in the underlying system will be `nil` valued. @table posix.sys.wait @int WNOHANG don't block waiting @int WUNTRACED report status of stopped children
static int Ptime(lua_State *L) { time_t t = time(NULL); checknargs(L, 0); if ((time_t) -1 == t) return pusherror(L, "time"); lua_pushinteger(L, t); return 1; } static const luaL_Reg posix_time_fns[] = { #if defined _XOPEN_REALTIME && _XOPEN_REALTIME != -1 LPOSIX_FUNC( Pclock_getres ), LPOSIX_FUNC( Pclock_gettime ), #endif LPOSIX_FUNC( Pgmtime ), LPOSIX_FUNC( Plocaltime ), LPOSIX_FUNC( Pmktime ), LPOSIX_FUNC( Pnanosleep ), LPOSIX_FUNC( Pstrftime ), LPOSIX_FUNC( Pstrptime ), LPOSIX_FUNC( Ptime ), {NULL, NULL} }; LUALIB_API int luaopen_posix_time(lua_State *L)
*/ static int Pfnmatch(lua_State *L) { const char *pattern = luaL_checkstring(L, 1); const char *string = luaL_checkstring(L, 2); int flags = optint(L, 3, 0); int res; checknargs(L, 3); return pushintresult(fnmatch(pattern, string, flags)); } static const luaL_Reg posix_fnmatch_fns[] = { LPOSIX_FUNC( Pfnmatch ), {NULL, NULL} }; /*** Constants. @section constants */ /*** Fnmatch constants. Any constants not available in the underlying system will be `nil` valued. @table posix.fnmatch @int FNM_PATHNAME slashes in pathname must be matched by slash in pattern @int FNM_NOESCAPE disable backslash escaping
lua_getfield(L, 3, "cc"); for (i=0; i<NCCS; i++) { lua_pushnumber(L, i); lua_gettable(L, -2); t.c_cc[i] = luaL_optint(L, -1, 0); lua_pop(L, 1); } return pushresult(L, tcsetattr(fd, act, &t), NULL); } static const luaL_Reg posix_termio_fns[] = { LPOSIX_FUNC( Ptcdrain ), LPOSIX_FUNC( Ptcflow ), LPOSIX_FUNC( Ptcflush ), LPOSIX_FUNC( Ptcgetattr ), LPOSIX_FUNC( Ptcsendbreak ), LPOSIX_FUNC( Ptcsetattr ), {NULL, NULL} }; LUALIB_API int luaopen_posix_termio(lua_State *L) { luaL_register(L, "posix.termio", posix_termio_fns); lua_pushliteral(L, "posix.termio for " LUA_VERSION " / " PACKAGE_STRING); lua_setfield(L, -2, "version");
@treturn int mask bit corresponding to *priority* @see setlogmask(3) */ static int PLOG_MASK(lua_State *L) { checknargs(L, 1); return pushintresult(LOG_MASK(checkint(L, 1))); } #endif static const luaL_Reg posix_syslog_fns[] = { #if LPOSIX_2001_COMPLIANT LPOSIX_FUNC( PLOG_MASK ), LPOSIX_FUNC( Popenlog ), LPOSIX_FUNC( Psyslog ), LPOSIX_FUNC( Pcloselog ), LPOSIX_FUNC( Psetlogmask ), #endif {NULL, NULL} }; /*** Constants. @section constants */ /***
{ int fd = checkint(L, 1); int offset = checkint(L, 2); int len = checkint(L, 3); int advice = checkint(L, 4); int r; checknargs(L, 4); r = posix_fadvise(fd, offset, len, advice); return pushresult(L, r == 0 ? 0 : -1, "posix_fadvise"); } #endif static const luaL_Reg posix_fcntl_fns[] = { LPOSIX_FUNC( Pfcntl ), LPOSIX_FUNC( Popen ), #if HAVE_POSIX_FADVISE LPOSIX_FUNC( Pposix_fadvise ), #endif {NULL, NULL} }; /*** Constants. @section constants */ /*** Fcntl constants.