Next: , Previous: , Up: Library   [Contents][Index]


5.28 System functions

Built-in Function: boolean access (string pathname, number mode)

Checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is dereferenced. The function returns ‘True’ if the file can be accessed and ‘False’ otherwise25.

Symbolic values for mode are provided in module status:

F_OK

Tests for the existence of the file.

R_OK

Tests whether the file exists and grants read permission.

W_OK

Tests whether the file exists and grants write permission.

X_OK

Tests whether the file exists and grants execute permission.

Built-in Function: string getenv (string name)

Searches the environment list for the variable name and returns its value. If the variable is not defined, the function raises the exception ‘e_not_found’.

Built-in Function: string gethostname ([bool fqn])

Return the host name of this machine.

If the optional fqn is given and is ‘true’, the function will attempt to return fully-qualified host name, by attempting to resolve it using DNS.

Built-in Function: string getdomainname ()

Return the domain name of this machine. Note, that it does not necessarily coincide with the actual machine name in DNS.

Depending on the underlying ‘libc’ implementation, this call may return empty string or the string ‘(none)’. Do not rely on it to get the real domain name of the box mailfromd runs on, use localdomain (see below) instead.

Library Function: string localdomain ()

Return the local domain name of this machine.

This function first uses getdomainname to make a first guess. If it does not return a meaningful value, localdomain calls gethostname(1) to determine the fully qualified host name of the machine, and returns its domain part.

To use this function, require the localdomain module (see Modules), e.g.: require localdomain.

Built-in Function: number time ()

Return the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds.

Built-in Function: string strftime (string fmt, number timestamp)
Built-in Function: string strftime (string fmt, number timestamp, boolean gmt)

Formats the time timestamp (seconds since the Epoch) according to the format specification format. Ordinary characters placed in the format string are copied to the output without conversion. Conversion specifiers are introduced by a ‘%’ character. See Time and Date Formats, for a detailed description of the conversion specifiers. We recommend using single quotes around fmt to prevent ‘%’ specifiers from being interpreted as Mailfromd variables (See Literals, for a discussion of quoted literals and variable interpretation within them).

The timestamp argument can be a return value of time function (see above).

For example:

strftime('%Y-%m-%d %H:%M:%S %Z', 1164477564)
 ⇒ 2006-11-25 19:59:24 EET
strftime('%Y-%m-%d %H:%M:%S %Z', 1164477564, 1)
 ⇒ 2006-11-25 17:59:24 GMT
Built-in Function: string uname (string format)

This function returns system information formatted according to the format specification format. Ordinary characters placed in the format string are copied to the output without conversion. Conversion specifiers are introduced by a ‘%’ character. The following conversions are defined:

%s

Name of this system.

%n

Name of this node within the communications network to which this node is attached. Note, that it does not necessarily coincide with the actual machine name in DNS.

%r

Kernel release.

%v

Kernel version.

%m

Name of the hardware type on which the system is running.

For example:

  uname('%n runs %s, release %r on %m')
    ⇒ "Trurl runs Linux, release 2.6.26 on i686"

Notice the use of single quotes.

Unlinks (deletes) the file name. On error, throws the e_failure exception.

Built-in Function: number system (string str)

The function system executes a command specified in str by calling /bin/sh -c string, and returns -1 on error or the return status of the command otherwise.

Built-in Function: void sleep (number secs[, usec])

Sleep for secs seconds. If optional usec argument is given, it specifies additional number of microseconds to wait for. For example, to suspend execution of the filter for 1.5 seconds:

  sleep(1,500000)

This function is intended mostly for debugging and experimental purposes.

Built-in Function: number umask (number mask)

Set the umask to mask & 0777. Return the previous value of the mask.


Footnotes

(25)

Note, that the return code is inverted in respect to the system function ‘access(2)’.


Next: , Previous: , Up: Library   [Contents][Index]