16 # include <type_traits>
24 # include <boost/lexical_cast.hpp>
44 #if !defined(PTRDIFF_MIN)
45 # if defined(__LP64__) && __LP64__
46 # define PTRDIFF_MIN -9223372036854775808LL
48 # define PTRDIFF_MIN -2147483648
52 #if !defined(PTRDIFF_MAX)
53 # if defined(__LP64__) && __LP64__
54 # define PTRDIFF_MAX 9223372036854775807LL
56 # define PTRDIFF_MAX 2147483647
94 QI_API FILE*
fopen(
const char *filename,
const char *mode);
170 QI_API bool fnmatch(
const std::string &pattern,
const std::string &
string);
184 QI_API int snprintf(
char *str,
size_t size,
const char *format, ...);
380 QI_API void *
dlopen(
const char *filename,
int flag = -1);
416 QI_API void *
dlsym(
void *handle,
const char *symbol);
571 QI_API std::map<std::string, std::vector<std::string> >
hostIPAddrs(
bool ipv6Addr =
false);
604 std::string _oldName;
671 template <
typename T>
678 return boost::lexical_cast<T>(sval);
687 static_assert(std::is_arithmetic<N>::value || std::is_enum<N>::value,
688 "to_string() accepts only arithmetic types (i.e. integral types and "
689 "floating-point types) and enum types.");
691 #if BOOST_OS_ANDROID && BOOST_COMP_GNUC
694 std::ostringstream stream;
704 #endif // _QI_OS_HPP_
qi::os::timeval operator-(const qi::os::timeval &lhs, const qi::os::timeval &rhs)
Substract two timeval together.
std::string getenv(const char *var)
Get an environment variable.
int gettid()
Get the thread identifier.
timeval(int64_t sec, int64_t usec)
int spawnlp(const char *argv,...)
Create and execute a new process.
Set the current thread name and restore it after use.
int stat(const char *filename, struct stat *pstat)
Get file status.
int setenv(const char *var, const char *value)
Change or add an environment variable.
bool isProcessRunning(int pid, const std::string &fileName=std::string())
Check whether a process is running, given its file name and pid.
int kill(int pid, int sig)
Send a signal to a process.
std::string generateUuid()
Generate a universally unique identifier.
T getEnvParam(const char *name, T defaultVal)
Returns the value of the environment variableif set, the defaultVal otherwise.
std::string timezone()
Return the timezone.
void msleep(unsigned int milliseconds)
Sleep for the specified number of milliseconds.
int spawnvp(char *const argv[])
Create and execute a new process.
std::pair< int64_t, int64_t > cputime()
Return CPU time used by the calling thread as a pair (userTime, systemTime) in microseconds.
void symlink(const qi::Path &source, const qi::Path &destination)
Create a symlink from source to destination.
int checkdbg()
Check if the current process is running into a debugger.
dll import/export and compiler message
const char * dlerror()
Returns a human readable string of the error code.
int unsetenv(const char *var)
Remove an environment variable.
std::string home()
Return path to the current user's HOME.
QI_API_DEPRECATED int gettimeofday(qi::os::timeval *tp)
The gettimeofday() function shall obtain the current time.
std::string currentThreadName()
returns the current thread name as a std::string
void * dlsym(void *handle, const char *symbol)
Get the address where the symbol is loaded into memory.
ScopedThreadName(const std::string &newName)
const Uuid & getMachineIdAsUuid()
Same as getMachineId but return a uuid and not its string representation.
void sleep(unsigned int seconds)
Sleep for the specified number of seconds.
std::string mktmpdir(const char *prefix="")
Return a writable temporary directory.
std::map< std::string, std::vector< std::string > > hostIPAddrs(bool ipv6Addr=false)
Find all network adapters and corresponding IPs.
bool fnmatch(const std::string &pattern, const std::string &string)
Implement POSIX compliant fnmatch.
SystemClock::time_point SystemClockTimePoint
System clock time point.
bool setCurrentThreadCPUAffinity(const std::vector< int > &cpus)
Set the CPU affinity for the current thread.
qi::int64_t tv_sec
seconds
std::string tmp()
Return the system's temporary directory.
std::string gethostname()
Get the system's hostname.
long numberOfCPUs()
Get the number of CPUs on the local machin.
qi::int64_t tv_usec
microseconds
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
The Path class allow handling filesystem path in a cross-platform maner. <includename>qi/path.hpp</includename> The class assume that all string are encoded in UTF-8 if not specified otherwise.
int isatty(int fd=1)
Test if descriptor represents a terminal.
std::string getMachineId()
Returns an unique uuid for the machine.
qi::int64_t ustime()
Elapsed time since program started in microseconds.
struct similar to POSIX timeval
int dlclose(void *handle)
Decrements the reference count on the dynamic library.
std::string pathsep()
Get the path separator.
int waitpid(int pid, int *status)
Wait for process to change state.
size_t memoryUsage(unsigned int pid)
Get the memory usage of a process in kB.
qi::os::timeval operator+(const qi::os::timeval &lhs, const qi::os::timeval &rhs)
Add two timeval together.
const Uuid & getProcessUuid()
Returns an unique uuid for the process.
T src(const std::atomic< T > &x)
FILE * fopen(const char *filename, const char *mode)
Open a file and returns and handle on it.
PtrUid ptrUid(void *address)
void setCurrentThreadName(const std::string &name)
Set the current thread name to the string in parameter.
int system(const char *command)
Execute a shell command.
std::string to_string(N n)
(Arithmetic or Enum) N
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
int snprintf(char *str, size_t size, const char *format,...)
Implement POSIX compliant snprintf.
void * dlopen(const char *filename, int flag=-1)
Load a dynamic library.
int getpid()
Get the process identifier.
char * strdup(const char *src)
Implement POSIX compliant strdup.
unsigned short findAvailablePort(unsigned short port)
Find the first available port starting at port number in parameter.