Uni/Unistd#

Thread and memory safe wrappers to various <unistd.h> functions.

Info

To use declarations from this page, include the <essence/uni/unistd.hpp> header.

They are found within the essence::uni namespace.

using groupid = gid_t#
using userid = uid_t#
using procid = pid_t#
enum class ok : u32#

Flags used for the access function to determine info about a file.

enumerator exists = F_OK#

The file exists.

enumerator read = R_OK#

The file can be read by the invoking user.

enumerator write = W_OK#

The file can be written to by the invoking user.

enumerator exec = X_OK#

The file is executable by the invoking user.

enumerator rw = R_OK | W_OK#

The file can be read and written to by the invoking user.

enumerator rwx = R_OK | W_OK | X_OK#

The file can be read, written to and executed by the invoking user.

enumerator all = F_OK | R_OK | W_OK | X_OK#

The file exists, can be read, written to and executed by the invoking user.

bool access(const std::string &path, ok flags = ok::exists)#

Check flags against the file at path

Returns true if the check succeeds, false if it fails for any reason.

The flags argument may be a bitwise-or combination of ok flags, a raw integer value, or a std::initializer_list of ok members.

Example

if (uni::access("/foo/bar/buzz", uni::ok::exists|uni::ok::exec))
{
   // the file exists and is executable
}
u32 alarm(u32 n)#

Deliver a SIGALRM to the calling process in n seconds.

std::string getcwd()#

Get the path to the current working directory.

Returns an empty string upon failure.

bool chdir(const std::string &path)#

Change the current working directory of the calling process to path.

Returns true upon success, false otherwise.

bool chown(const std::string &path, userid u, groupid g)#

Change the ownership of path the the user u and group g.

Returns true upon success, false otherwise.

userid getuid()#

Get the user id of the calling process invoker.

groupid geteuid()#

Get the effective user id of the calling process invoker.

groupid getgid()#

Get the group id of the calling process invoker.

groupid getegid()#

Get the effective group id of the calling process invoker.

std::vector<groupid> getgroups()#

Get the IDs of the groups which the process invoker belongs to.

Returns an empty vector upon failure.

i64 gethostid()#

Get the unique identifier of the host machine.

std::string gethostname()#

Get the hostname of the current machine.

Returns an empty string upon failure.

std::string getlogin()#

Get the username of the invoking user.

Returns an empty string upon failure.

procid getpgid(procid p)#

Get the process group id of PID p.

procid getpid()#

Get the PID of current process.

procid getppid()#

Get the PID of the current process’s parent.

bool isatty(i32 fd = STDOUT_FILENO)#

Check if fd is a TTY.

std::string ttyname(i32 fd = STDOUT_FILENO)#

Get the name of the TTY at file descriptor fd.

Returns an empty string if fd is not associated with a TTY.

bool unlink(const std::string &path)#

Remove (unlink) the file at path.

Returns false upon failure to unlink, true upon success.

bool symlink(const std::string &from, const std::string &to)#

Create a symbolic link of from to destination to.

Returns false upon failure, true upon success.

std::string readlink(const std::string &path)#

Return the destination of the symbolic link at path.

If path is not a symbolic link, returns the value of path.