DDraceNetwork Docs
Shell

Classes

class  CCmdlineFix
 

Typedefs

typedef pid_t PROCESS
 

Enumerations

enum class  EShellExecuteWindowState { EShellExecuteWindowState::FOREGROUND , EShellExecuteWindowState::BACKGROUND }
 

Functions

int pid ()
 
void cmdline_fix (int *argc, const char ***argv)
 
void cmdline_free (int argc, const char **argv)
 
PROCESS shell_execute (const char *file, EShellExecuteWindowState window_state)
 
int kill_process (PROCESS process)
 
bool is_process_alive (PROCESS process)
 
int open_link (const char *link)
 
int open_file (const char *path)
 
bool os_version_str (char *version, size_t length)
 
void os_locale_str (char *locale, size_t length)
 

Variables

constexpr PROCESS INVALID_PROCESS = 0
 

Detailed Description

Shell, process management, OS specific functionality.

Typedef Documentation

◆ PROCESS

typedef pid_t PROCESS

A handle for a process.

Enumeration Type Documentation

◆ EShellExecuteWindowState

enum class EShellExecuteWindowState
strong

Determines the initial window state when using shell_execute to execute a process.

Remarks
Currently only supported on Windows.
Enumerator
FOREGROUND 

The process window is opened in the foreground and activated.

BACKGROUND 

The process window is opened in the background without focus.

Function Documentation

◆ cmdline_fix()

void cmdline_fix ( int *  argc,
const char ***  argv 
)

Fixes the command line arguments to be encoded in UTF-8 on all systems.

Parameters
argcA pointer to the argc parameter that was passed to the main function.
argvA pointer to the argv parameter that was passed to the main function.
Remarks
You need to call cmdline_free once you're no longer using the results.

◆ cmdline_free()

void cmdline_free ( int  argc,
const char **  argv 
)

Frees memory that was allocated by cmdline_fix.

Parameters
argcThe argc obtained from cmdline_fix.
argvThe argv obtained from cmdline_fix.

◆ is_process_alive()

bool is_process_alive ( PROCESS  process)

Checks if a process is alive.

Parameters
processHandle/PID of the process.
Returns
true if the process is currently running, false if the process is not running (dead).

◆ kill_process()

int kill_process ( PROCESS  process)

Sends kill signal to a process.

Parameters
processHandle of the process to kill.
Returns
1 on success, 0 on error.

◆ open_file()

int open_file ( const char *  path)

Opens a file or directory with the default program.

Parameters
pathThe file or folder to open with the default program.
Returns
1 on success, 0 on failure.
Remarks
The strings are treated as zero-terminated strings.
This may not be called with untrusted input or it'll result in arbitrary code execution, especially on Windows.

◆ open_link()

int open_link ( const char *  link)

Opens a link in the browser.

Parameters
linkThe link to open in a browser.
Returns
1 on success, 0 on failure.
Remarks
The strings are treated as zero-terminated strings.
This may not be called with untrusted input or it'll result in arbitrary code execution, especially on Windows.

◆ os_locale_str()

void os_locale_str ( char *  locale,
size_t  length 
)

Returns a string of the preferred locale of the user / operating system. The string conforms to RFC 3066 and only contains the characters a-z, A-Z, 0-9 and -. If the preferred locale could not be determined this function falls back to the locale "en-US".

Parameters
localeBuffer to use for the output.
lengthLength of the output buffer.
Remarks
The destination buffer will be zero-terminated.

◆ os_version_str()

bool os_version_str ( char *  version,
size_t  length 
)

Returns a human-readable version string of the operating system.

Parameters
versionBuffer to use for the output.
lengthLength of the output buffer.
Returns
true on success, false on failure.

◆ pid()

int pid ( )

Returns the ID of the current process.

Returns
PID of the current process.

◆ shell_execute()

PROCESS shell_execute ( const char *  file,
EShellExecuteWindowState  window_state 
)

Executes a given file.

Parameters
fileThe file to execute.
window_stateThe window state how the process window should be shown.
Returns
Handle of the new process, or INVALID_PROCESS on error.

Variable Documentation

◆ INVALID_PROCESS

constexpr PROCESS INVALID_PROCESS = 0
constexpr

A handle that denotes an invalid process.