uvw 2.12.1
Loading...
Searching...
No Matches
uvw::Utilities::OS Struct Reference

OS dedicated utilities. More...

#include <util.h>

Static Public Member Functions

static PidType pid () noexcept
 Returns the current process id.
 
static PidType parent () noexcept
 Returns the parent process id.
 
static std::string homedir () noexcept
 Gets the current user's home directory.
 
static std::string tmpdir () noexcept
 Gets the temp directory.
 
static std::string env (const std::string &name) noexcept
 Retrieves an environment variable.
 
static bool env (const std::string &name, const std::string &value) noexcept
 Creates, updates or deletes an environment variable.
 
template<typename Func >
static std::enable_if_t< std::is_invocable_v< Func, std::string_view, std::string_view >, bool > env (Func func) noexcept
 Retrieves all environment variables and iterates them.
 
static std::string hostname () noexcept
 Returns the hostname.
 
static UtsName uname () noexcept
 Gets name and information about the current kernel.
 
static Passwd passwd () noexcept
 Gets a subset of the password file entry.
 
static int priority (PidType pid)
 Retrieves the scheduling priority of a process.
 
static bool priority (PidType pid, int prio)
 Sets the scheduling priority of a process.
 

Detailed Description

OS dedicated utilities.

Definition at line 469 of file util.h.

Member Function Documentation

◆ env() [1/3]

static std::string uvw::Utilities::OS::env ( const std::string & name)
staticnoexcept

Retrieves an environment variable.

Parameters
nameThe name of the variable to be retrieved.
Returns
The value of the environment variable, an empty string in case of errors.

◆ env() [2/3]

static bool uvw::Utilities::OS::env ( const std::string & name,
const std::string & value )
staticnoexcept

Creates, updates or deletes an environment variable.

Parameters
nameThe name of the variable to be updated.
valueThe value to be used for the variable (an empty string to unset it).
Returns
True in case of success, false otherwise.

◆ env() [3/3]

template<typename Func >
static std::enable_if_t< std::is_invocable_v< Func, std::string_view, std::string_view >, bool > uvw::Utilities::OS::env ( Func func)
inlinestaticnoexcept

Retrieves all environment variables and iterates them.

Environment variables are passed one at a time to the callback in the form of std::string_views.
The signature of the function call operator must be such that it accepts two parameters, the name and the value of the i-th variable.

Template Parameters
FuncType of a function object to which to pass environment variables.
Parameters
funcA function object to which to pass environment variables.
Returns
True in case of success, false otherwise.

Definition at line 547 of file util.h.

◆ homedir()

static std::string uvw::Utilities::OS::homedir ( )
staticnoexcept

Gets the current user's home directory.

See the official documentation for further details.

Returns
The current user's home directory, an empty string in case of errors.

◆ hostname()

static std::string uvw::Utilities::OS::hostname ( )
staticnoexcept

Returns the hostname.

Returns
The hostname, an empty string in case of errors.

◆ parent()

static PidType uvw::Utilities::OS::parent ( )
staticnoexcept

Returns the parent process id.

See the official documentation for further details.

Returns
The parent process id.

◆ passwd()

static Passwd uvw::Utilities::OS::passwd ( )
staticnoexcept

Gets a subset of the password file entry.

This function can be used to get the subset of the password file entry for the current effective uid (not the real uid).

See the official documentation for further details.

Returns
The accessible subset of the password file entry.

◆ pid()

static PidType uvw::Utilities::OS::pid ( )
staticnoexcept

Returns the current process id.

See the official documentation for further details.

Returns
The current process id.

◆ priority() [1/2]

static int uvw::Utilities::OS::priority ( PidType pid)
static

Retrieves the scheduling priority of a process.

The returned value is between -20 (high priority) and 19 (low priority). A value that is out of range is returned in case of errors.

Note
On Windows, the result won't equal necessarily the exact value of the priority because of a mapping to a Windows priority class.
Parameters
pidA valid process id.
Returns
The scheduling priority of the process.

◆ priority() [2/2]

static bool uvw::Utilities::OS::priority ( PidType pid,
int prio )
static

Sets the scheduling priority of a process.

The returned value range is between -20 (high priority) and 19 (low priority).

Note
On Windows, the priority is mapped to a Windows priority class. When retrieving the process priority, the result won't equal necessarily the exact value of the priority.
Parameters
pidA valid process id.
prioThe scheduling priority to set to the process.
Returns
True in case of success, false otherwise.

◆ tmpdir()

static std::string uvw::Utilities::OS::tmpdir ( )
staticnoexcept

Gets the temp directory.

See the official documentation for further details.

Returns
The temp directory, an empty string in case of errors.

◆ uname()

static UtsName uvw::Utilities::OS::uname ( )
staticnoexcept

Gets name and information about the current kernel.

This function can be used to get name and information about the current kernel. The populated data includes the operating system name, release, version, and machine.

Returns
Name and information about the current kernel.

The documentation for this struct was generated from the following file: