Module posix

Lua POSIX bindings.

In addition to the convenience functions documented in this module, all APIs from submodules are copied into the return table for convenience and backwards compatibility.

Functions

chmod (path, mode) Change the mode of the path.
creat (path, mode) Create a file.
euidaccess (file, mode) Check permissions like posix.unistd.access, but for euid.
mkdir (path) Make a directory.
mkfifo (path) Make a FIFO pipe.
msgget (key[, flags=0[, mode="rw-rw-rw-"]]) Get a message queue identifier
open (path, oflags, modestr) Open a file.
pipeline (t, opt) Perform a series of commands and Lua functions as a pipeline.
pipeline_iterator (t, opt) Perform a series of commands and Lua functions as a pipeline, returning the output of the last stage's stdout as the values of an iterator.
pipeline_slurp (t, opt) Perform a series of commands and Lua functions as a pipeline.
setlogmask (...) Set log priority mask
spawn (task, ...) Run a command or function in a sub-process.
timeradd (x, y) Add one gettimeofday() returned timeval to another.
timercmp (x, y) Compare one gettimeofday() returned timeval with another
timersub (x, y) Subtract one gettimeofday() returned timeval from another.
umask ([mode]) Set file mode creation mask.


Functions

chmod (path, mode)
Change the mode of the path.

Parameters:

  • path string existing file path
  • mode string

    one of the following formats:

    • "rwxrwxrwx" (e.g. "rw-rw-r--")
    • "ugo+-=rwx" (e.g. "u+w")
    • +-=rwx" (e.g. "+w")

Returns:

    int 0, if successful

Or

  1. nil
  2. string error message
  3. int errnum

See also:

Usage:

    P.chmod ('bin/dof', '+x')
creat (path, mode)
Create a file. This function is obsoleted by posix.fcntl.open with posix.O_CREAT.

Parameters:

  • path string name of file to create
  • mode string permissions with which to create file

Returns:

    int file descriptor of file at path, if successful

Or

  1. nil
  2. string error message
  3. int errnum

See also:

Usage:

    fd = P.creat ("data", "rw-r-----")
euidaccess (file, mode)
Check permissions like posix.unistd.access, but for euid. Based on the glibc function of the same name. Does not always check for read-only file system, text busy, etc., and does not work with ACLs &c.

Parameters:

  • file string file to check
  • mode string checks to perform (as for access)

Returns:

    0 if access allowed; nil otherwise (and errno is set)
mkdir (path)
Make a directory.

Parameters:

  • path string location in file system to create directory

Returns:

    int 0, if successful

Or

  1. nil
  2. string error message
  3. int errnum
mkfifo (path)
Make a FIFO pipe.

Parameters:

  • path string location in file system to create fifo

Returns:

    int 0, if successful

Or

  1. nil
  2. string error message
  3. int errnum
msgget (key[, flags=0[, mode="rw-rw-rw-"]])
Get a message queue identifier

Parameters:

  • key int message queue id, or IPC_PRIVATE for a new queue
  • flags int bitwise OR of zero or more from IPC_CREAT and IPC_EXCL (default 0)
  • mode string execute bits are ignored (default "rw-rw-rw-")

Returns:

    int message queue identifier, if successful

Or

  1. nil
  2. string error message
  3. int errnum

See also:

open (path, oflags, modestr)
Open a file.

Parameters:

  • path string file to act on
  • oflags int bitwise OR of zero or more of O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_CREAT, O_DSYNC, O_EXCL, O_NOCTTY, O_NONBLOCK, O_RSYNC, O_SYNC, O_TRUNC
  • modestr string (used with O_CREAT; see chmod for format)

Returns:

    int file descriptor for path, if successful

Or

  1. nil
  2. string error message
  3. int errnum

See also:

Usage:

    fd = P.open ("data", bit.bor (P.O_CREAT, P.O_RDWR), "rw-r-----")
pipeline (t, opt)
Perform a series of commands and Lua functions as a pipeline.

Parameters:

Returns:

    int exit code of the chain
pipeline_iterator (t, opt)
Perform a series of commands and Lua functions as a pipeline, returning the output of the last stage's stdout as the values of an iterator.

Parameters:

Returns:

    iterator function returning a chunk of output on each call
pipeline_slurp (t, opt)
Perform a series of commands and Lua functions as a pipeline. Return the output of the last stage's stdout.

Parameters:

Returns:

    string output of the pipeline
setlogmask (...)
Set log priority mask

Parameters:

  • ... int zero or more of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_WARNING, LOG_NOTICE, LOG_INFO and LOG_DEBUG

Returns:

    int 0, if successful

Or

  1. nil
  2. string error message
  3. int errnum
spawn (task, ...)
Run a command or function in a sub-process.

Parameters:

  • task , a string to be executed as a shell command, or a table of arguments to P.execp or a Lua function, which should read from standard input, write to standard output, and return an exit code
  • ... string positional arguments to the program or function

Returns:

  1. int status exit code, if successful
  2. string exit type, if wait succeeds

Or

  1. nil
  2. string error message
timeradd (x, y)
Add one gettimeofday() returned timeval to another.

Parameters:

  • x a timeval
  • y another timeval

Returns:

    x + y, adjusted for usec overflow
timercmp (x, y)
Compare one gettimeofday() returned timeval with another

Parameters:

  • x a timeval
  • y another timeval

Returns:

    0 if x and y are equal, >0 if x is newer, <0 if y is newer
timersub (x, y)
Subtract one gettimeofday() returned timeval from another.

Parameters:

  • x a timeval
  • y another timeval

Returns:

    x - y, adjusted for usec underflow
umask ([mode])
Set file mode creation mask.

Parameters:

  • mode string file creation mask string (optional)

Returns:

    string previous umask

See also:

generated by LDoc 1.4.3 Last updated 2015-01-04 12:06:34