Module posix.stdio

A few Standard I/O functions not already in Lua core.

Functions

ctermid () Name of controlling terminal.
fdopen (fd, mode) Create a Lua file object from a file descriptor.
fileno (file) File descriptor corresponding to a Lua file object.
rename (oldpath, newpath) Change the name or location of a file

Constants

posix.stdio Stdio constants.


Functions

ctermid ()
Name of controlling terminal.

Returns:

    string controlling terminal for current process

See also:

fdopen (fd, mode)
Create a Lua file object from a file descriptor.

Parameters:

  • fd int file descriptor
  • mode string the mode in which to open the file descriptor

Returns:

    file Lua file object fd, if successful

Or

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

See also:

Usage:

    local fdopen = require "posix.stdio".fdopen
    local STDOUT_FILENO = require "posix.unistd".STDOUT_FILENO
    stdout = fdopen (STDOUT_FILENO, "w")
fileno (file)
File descriptor corresponding to a Lua file object.

Parameters:

  • file file Lua file object

Returns:

    int file descriptor for file, if successful

Or

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

See also:

Usage:

    local stdio = require "posix.stdio"
    local unistd = require "posix.unistd"
    assert (stdio.fileno (io.stdout) == unistd.STDOUT_FILENO)
rename (oldpath, newpath)
Change the name or location of a file

Parameters:

Returns:

    int 0, if successful

Or

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

See also:

Usage:

    local ok, errmsg = P.rename (oldpath, newpath)
    if not ok then error (errmsg) end

Constants

posix.stdio
Stdio constants. Any constants not available in the underlying system will be nil valued.

Fields:

  • _IOFBF int fully buffered
  • _IOLBF int line buffered
  • _IONBF int unbuffered
  • BUFSIZ int size of buffer
  • EOF int end of file
  • FOPEN_MAX int maximum number of open files
  • FILENAME_MAX int maximum length of filename

Usage:

    -- Print stdio constants supported on this host.
    for name, value in pairs (require "posix.stdio") do
      if type (value) == "number" then
        print (name, value)
       end
    end
generated by LDoc 1.5.0 Last updated 2023-06-16 20:19:12