libqi
1.12
|
cross-platform os related function. (mostly following POSIX convention)
More...
Classes | |
struct | qi::os::timeval |
qi::os::timeval struct similar to POSIX timeval More... | |
Namespaces | |
namespace | qi::os |
OS abstraction layer. | |
Functions | |
QI_API FILE * | qi::os::fopen (const char *filename, const char *mode) |
Open a file. | |
QI_API int | qi::os::stat (const char *filename, struct stat *pstat) |
Get file status. | |
QI_API int | qi::os::checkdbg () |
Check if the current program is running under a debugger. | |
QI_API std::string | qi::os::home () |
Return path to the current user's HOME. | |
QI_API std::string | qi::os::tmpdir (const char *prefix="") |
Return a temporary directoryThe directory is writeable and exits. The caller is responsible of destroying the temporary directory. | |
Environment Functions | |
QI_API std::string | qi::os::getenv (const char *var) |
Get an environment variable. | |
QI_API int | qi::os::setenv (const char *var, const char *value) |
Change or add an environment variable. | |
Time Functions | |
QI_API void | qi::os::sleep (unsigned int seconds) |
Sleep for the specified number of seconds. | |
QI_API void | qi::os::msleep (unsigned int milliseconds) |
Sleep for the specified number of milliseconds. | |
QI_API int | qi::os::gettimeofday (qi::os::timeval *tp) |
The gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified. This clock is subject to NTP adjustments. | |
Shared Library Functions | |
QI_API void * | qi::os::dlopen (const char *filename, int flag=-1) |
Loads dynamic library. | |
QI_API int | qi::os::dlclose (void *handle) |
Decrements the reference count on the dynamic library. | |
QI_API void * | qi::os::dlsym (void *handle, const char *symbol) |
Get the address where the symbol is loaded into memory. | |
QI_API const char * | qi::os::dlerror (void) |
Returns a human readable string. | |
Process Functions | |
QI_API int | qi::os::spawnvp (char *const argv[]) |
Create and execute a new process. | |
QI_API int | qi::os::spawnlp (const char *argv,...) |
Create and execute a new process. | |
QI_API int | qi::os::system (const char *command) |
Execute a shell command. | |
QI_API int | qi::os::waitpid (int pid, int *status) |
Wait for process to change state. |
cross-platform os related function. (mostly following POSIX convention)
#include <qi/os.hpp>
Include POSIX compatibility support for OS not following POSIX. This namespace provide abstracted OS functions working on three operatrion system (Linux, MacOS, Windows) with the same behavior.
Features:
qi::os::checkdbg | ( | ) |
Check if the current program is running under a debugger.
int qi::os::dlclose | ( | void * | handle | ) |
Decrements the reference count on the dynamic library.
Decrements the reference count on the dynamic library handle. If the reference count drops to zero and no other loaded libraries use symbols in it, then the dynamic library is unloaded.
handle | The dynamic library handle. |
const char * qi::os::dlerror | ( | void | ) |
Returns a human readable string.
Returns a human readable string describing the most recent error that occurred from dlopen(), dlsym() or dlclose() since the last call to dlerror().
void * qi::os::dlopen | ( | const char * | filename, |
int | flag = -1 |
||
) |
Loads dynamic library.
Loads the dynamic library file named by the null-terminated string filename and returns an opaque "handle" for the dynamic library. If filename is NULL, then the returned handle is for the main program.
filename | Name of the dynamic library. |
flag | Flags to load the dynamic library. |
void * qi::os::dlsym | ( | void * | handle, |
const char * | symbol | ||
) |
Get the address where the symbol is loaded into memory.
If the symbol is not found, in the specified library or any of the libraries that were automatically loaded by dlopen() when that library was loaded, dlsym() returns NULL.
handle | Handle of a dynamic library returned by dlopen(). |
symbol | The null-terminated symbol name. |
int qi::os::fopen | ( | const char * | filename, |
const char * | mode | ||
) |
Open a file.
Nothing special under posix systems, it's only useful for Windows, where files should be open using a widestring. Refer to 'man 3 fopen' for more informations, and to the documentation of _wfopen on MSDN to understand the Windows behaviors.
filename | Path to the file (in UTF-8). |
mode | The mode. |
std::string qi::os::getenv | ( | const char * | var | ) |
Get an environment variable.
Searches the environment list to find the environment variable var, and returns a pointer to the corresponding value string.
var | The environment variable to search for. |
int qi::os::gettimeofday | ( | qi::os::timeval * | tp | ) |
The gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified. This clock is subject to NTP adjustments.
tp | the timeval structure used to return the current time |
void qi::os::msleep | ( | unsigned int | milliseconds | ) |
Sleep for the specified number of milliseconds.
Under Linux/OSX it will not be disturbed by eventual signals. Makes the calling thread sleep until millliseconds have elapsed or a signal arrives which is not ignored.
milliseconds | Number of milliseconds to sleep for |
int qi::os::setenv | ( | const char * | var, |
const char * | value | ||
) |
Change or add an environment variable.
Adds the variable name to the environment with the value var, if name does not already exist. If var does exist in the environment, then its value is changed to value
var | The variable name. |
value | The value of the variable. |
void qi::os::sleep | ( | unsigned int | seconds | ) |
Sleep for the specified number of seconds.
Under Linux/OSX it will not be disturbed by eventual signals. Makes the calling thread sleep until seconds have elapsed or a signal arrives which is not ignored.
seconds | Number of second to sleep for |
int qi::os::spawnlp | ( | const char * | argv, |
... | |||
) |
Create and execute a new process.
Creates and executes a new process
argv | Path of file to be executed. |
... | The command line arguments of the new process as var args. |
int qi::os::spawnvp | ( | char *const | argv[] | ) |
Create and execute a new process.
Creates and executes a new process.
argv | The command line arguments of the new process as an array (NULL terminated). |
int qi::os::stat | ( | const char * | filename, |
struct stat * | pstat | ||
) |
Get file status.
Stats the file pointed to by filename and fills in pstat. You need to include <sys/stat.h> to get access to struct.
filename | Path to the file (in UTF-8). |
pstat | A pointer to a struct stat that will be filled by the function. |
int qi::os::system | ( | const char * | command | ) |
Execute a shell command.
Executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed.
command | Command to execute. |
std::string qi::os::tmpdir | ( | const char * | prefix = "" | ) |
Return a temporary directoryThe directory is writeable and exits. The caller is responsible of destroying the temporary directory.
prefix | Prefix of the tmp file (in UTF-8). |
int qi::os::waitpid | ( | int | pid, |
int * | status | ||
) |
Wait for process to change state.
Suspends execution of the calling process until a child specified by pid argument has changed state.
pid | Pid to wait |
status | Pointer to a buffer where the return code of the specified process will be stored, or NULL. |