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
accessfunction 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.
-
enumerator exists = F_OK#
-
bool access(const std::string &path, ok flags = ok::exists)#
Check
flagsagainst the file atpathReturns
trueif the check succeeds,falseif it fails for any reason.The
flagsargument 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 }
-
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
trueupon success,falseotherwise.
-
bool chown(const std::string &path, userid u, groupid g)#
Change the ownership of
paththe the useruand groupg.Returns
trueupon success,falseotherwise.
-
std::vector<groupid> getgroups()#
Get the IDs of the groups which the process invoker belongs to.
Returns an empty vector upon failure.
-
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.
-
std::string ttyname(i32 fd = STDOUT_FILENO)#
Get the name of the TTY at file descriptor
fd.Returns an empty string if
fdis not associated with a TTY.
-
bool unlink(const std::string &path)#
Remove (unlink) the file at
path.Returns
falseupon failure to unlink,trueupon success.
-
bool symlink(const std::string &from, const std::string &to)#
Create a symbolic link of
fromto destinationto.Returns
falseupon failure,trueupon success.
-
std::string readlink(const std::string &path)#
Return the destination of the symbolic link at
path.If
pathis not a symbolic link, returns the value ofpath.