Abstracted functions pertaining to other areas. More...
Data Structures | |
struct | ruTimeVal |
Abstracted version of the Posix struct timeval. More... | |
struct | ruTryLoop |
Macros | |
#define | RU_SIZE_AUTO (~0LU) |
Says to determine the size parameter using strlen or an equivalent. More... | |
#define | RU_NON_BLOCK (-1) |
Indicates that an operation is non blocking. Used by ruRunProg. More... | |
#define | RU_NO_TIMEOUT 0 |
Indicates that an operation that has no timeout. Used by ruRunProg. More... | |
#define | ruSleep(secs) ruSleepMs(((msec_t)(secs))*1000) |
Sleeps for the given number of seconds. More... | |
#define | ruRetWithCode(ptr, code, res) |
Convenience macro for setting a potentially passed in result pointer and returning a result. More... | |
#define | RU_IP4 0x1 |
Used by ruIpAddrs to specify filtering for IPv4 numbers. More... | |
#define | RU_IP6 0x2 |
Used by ruIpAddrs to specify filtering for IPv6 numbers. More... | |
#define | RU_IP (RU_IP4 | RU_IP6) |
Used by ruIpAddrs to specify filtering for IP numbers. More... | |
Typedefs | |
typedef signed long | rusize_s |
Abstracted version of size_t but signed. More... | |
typedef pid_t | ru_pid |
Abstracted process id type. More... | |
typedef const char * | perm_chars |
A permanent NULL terminated string pointer. More... | |
typedef const char * | trans_chars |
A transient NULL terminated string pointer. More... | |
typedef char * | alloc_chars |
An allocated NULL terminated string pointer. More... | |
typedef const uint16_t * | perm_uni |
A permanent UTF16 wchar_t character type. More... | |
typedef const uint16_t * | trans_uni |
A transient UTF16 wchar_t character type. More... | |
typedef uint16_t * | alloc_uni |
An allocated UTF16 wchar_t character type. More... | |
typedef const unsigned char * | perm_bytes |
A permanent data bytes pointer. More... | |
typedef const unsigned char * | trans_bytes |
A transient data bytes pointer. More... | |
typedef unsigned char * | alloc_bytes |
An allocated data bytes pointer. More... | |
typedef const void * | perm_ptr |
A permanent pointer. More... | |
typedef const void * | trans_ptr |
A transient pointer. More... | |
typedef void * | alloc_ptr |
An allocated pointer. More... | |
typedef void * | ptr |
A generic pointer. More... | |
typedef long | sec_t |
A signed type for expressing seconds. More... | |
typedef int64_t | msec_t |
A signed type for expressing milli seconds. More... | |
typedef int64_t | usec_t |
A signed type for expressing micro seconds. More... | |
typedef intptr_t | ru_int |
A pointer sized integer type for collections like ruMap or ruList. More... | |
typedef uintptr_t | ru_uint |
A pointer sized unsigned integer type for collections like ruMap or ruList. More... | |
typedef size_t | rusize |
Abstracted version of size_t. More... | |
Functions | |
RUAPI const char * | ruVersion (void) |
Returns the build version of this package. More... | |
RUAPI const char * | ruLastError (void) |
Returns an English textual representation of the last error this thread generated. More... | |
RUAPI perm_chars | ruGetOs (void) |
Returns a lowercase string representation of the current OS. More... | |
RUAPI alloc_chars | ruGetHostname (void) |
Returns the name of this host. More... | |
RUAPI trans_chars | ruGetenv (trans_chars variable) |
Returns the value of the requested environment vartiable or NULL if it is not set. More... | |
RUAPI ru_pid | ruProcessId (void) |
Return the current process id. More... | |
RUAPI int32_t | ruRunProg (const char **argv, sec_t timeout) |
Runs given program. More... | |
RUAPI alloc_chars | ruGetLanguage (void) |
Returns the ISO-639-1 2 letter country code pertaining to the running system,. More... | |
RUAPI unsigned long | ruSemiRandomNumber (unsigned long max, long offset) |
Returns a quasi ramdom number between 0 and max + offset. More... | |
RUAPI int | ruVersionComp (trans_chars ver1, trans_chars ver2) |
Compares 2 version strings This function compares version number strings that are made up of real numbers. The advantage is that the delimiter does not matter. It will work with, for example, 141.01.03, 141:1:3, or even 141A1P3. It also handles mismatched tails so that 141.1.3 will come before 141.1.3.1. Finally NULLs are also properly compared. More... | |
RUAPI int32_t | ruGetTimeVal (ruTimeVal *result) |
Returns a ruTimeVal representing the current time. More... | |
RUAPI usec_t | ruTimeUs (void) |
Return the current local time in microseconds since Jan. 1 1970. More... | |
RUAPI msec_t | ruTimeMs (void) |
Return the current local time in milliseconds since Jan. 1 1970. More... | |
RUAPI sec_t | ruTimeSec (void) |
Return the current local time in seconds since Jan. 1 1970. More... | |
RUAPI bool | ruTimeUsEllapsed (usec_t stamp) |
Checks if given stamp has elapsed. More... | |
RUAPI bool | ruTimeMsEllapsed (msec_t stamp) |
Checks if given stamp has elapsed. More... | |
RUAPI bool | ruTimeEllapsed (sec_t stamp) |
Checks if given stamp has elapsed. More... | |
RUAPI void | ruSleepUs (usec_t microseconds) |
Sleeps for the given number of micro seconds. More... | |
RUAPI void | ruSleepMs (msec_t milliseconds) |
Sleeps for the given number of milli seconds. More... | |
RUAPI void | ruTryLoopInit (ruTryLoop *cycle, msec_t retryMs, msec_t timeoutMs) |
RUAPI bool | ruTryLoopDone (ruTryLoop *cycle) |
RUAPI sec_t | ruTimeParse (trans_chars dateformat, trans_chars datestr) |
Convert a string representation of time to a time stamp. More... | |
RUAPI sec_t | ruUtcParse (trans_chars dateformat, trans_chars datestr) |
UTC version of ruTimeParse. More... | |
RUAPI int | ruTimeFormat (trans_chars format, rusize len, alloc_chars timeStr, sec_t timesecs) |
Return the current local time formatted in given buffer. More... | |
RUAPI int | ruUtcFormat (trans_chars format, rusize len, alloc_chars timeStr, sec_t timesecs) |
UTC version of ruTimeFormat. More... | |
RUAPI sec_t | ruTimeLocalToUtc (sec_t stamp) |
Converts given local time stamp to UTC. More... | |
RUAPI sec_t | ruTimeUtcToLocal (sec_t stamp) |
Converts given UTC time stamp to local time. More... | |
RUAPI ptr | ruCharPtrDup (char *in) |
Copies the given string and returns the pointer. More... | |
RUAPI ruList | ruIpAddrs (int32_t ipfilter) |
Returns the IP numbers bound to the host. More... | |
RUAPI int32_t | ruGetOptMap (ruMap *parms, trans_chars opts, int argc, char **argv) |
Runs getopt short with given parameters. More... | |
Abstracted functions pertaining to other areas.
#define RU_IP4 0x1 |
Used by ruIpAddrs to specify filtering for IPv4 numbers.
#define RU_IP6 0x2 |
Used by ruIpAddrs to specify filtering for IPv6 numbers.
#define RU_NO_TIMEOUT 0 |
Indicates that an operation that has no timeout. Used by ruRunProg.
#define RU_NON_BLOCK (-1) |
Indicates that an operation is non blocking. Used by ruRunProg.
#define RU_SIZE_AUTO (~0LU) |
Says to determine the size parameter using strlen or an equivalent.
#define ruRetWithCode | ( | ptr, | |
code, | |||
res | |||
) |
Sleeps for the given number of seconds.
secs | time to sleep |
typedef unsigned char* alloc_bytes |
An allocated data bytes pointer.
On input this can represent a place on the stack or heap that will be written to by the called function. Usually accompanied by a length parameter. It can also represent a parameter that will be freed in conjunction with an enclosing object after use. On output this data belongs to the caller and must be freed after use. Within functions this can also be used for data pointers that must be freed.
typedef char* alloc_chars |
An allocated NULL terminated string pointer.
On input this can represent a place on the stack or heap that will be written to by the called function. Usually accompanied by a length parameter. It can also represent a parameter that will be freed in conjunction with an enclosing object after use. On output this string belongs to the caller and must be freed after use. Within functions this can also be used for string pointers that must be freed.
typedef void* alloc_ptr |
An allocated pointer.
On input this can represent a place on the stack or heap that will be written to by the called function. Usually accompanied by a length parameter. It can also represent a parameter that will be freed in conjunction with an enclosing object after use. On output this object belongs to the caller and must be freed after use.
typedef uint16_t* alloc_uni |
An allocated UTF16 wchar_t character type.
On input this can represent a place on the stack or heap that will be written to by the called function. Usually accompanied by a length parameter. It can also represent a parameter that will be freed in conjunction with an enclosing object after use. On output this data belongs to the caller and must be freed after use. Within functions this can also be used for data pointers that must be freed.
typedef int64_t msec_t |
A signed type for expressing milli seconds.
typedef const unsigned char* perm_bytes |
A permanent data bytes pointer.
On input it needs to persist through the life of a given context. On output it is guaranteed to live as long as it's context or until it has been explicitly finalized. It must not be freed. Within functions this can also be used for string pointers that must not be freed.
typedef const char* perm_chars |
A permanent NULL terminated string pointer.
On input it needs to persist through the life of a given context. On output it is guaranteed to live as long as it's context or until it has been explicitly finalized. It must not be freed. Within functions this can also be used for string pointers that must not be freed.
typedef const void* perm_ptr |
A permanent pointer.
On input it needs to persist through the life of a given context. On output it is guaranteed to live as long as it's context or until it has been explicitly finalized. It must not be freed.
typedef const uint16_t* perm_uni |
A permanent UTF16 wchar_t character type.
On input it needs to persist through the life of a given context. On output it is guaranteed to live as long as it's context or until it has been explicitly finalized. It must not be freed. Within functions this can also be used for string pointers that must not be freed.
typedef void* ptr |
A generic pointer.
typedef pid_t ru_pid |
Abstracted process id type.
typedef uintptr_t ru_uint |
typedef size_t rusize |
Abstracted version of size_t.
typedef signed long rusize_s |
Abstracted version of size_t but signed.
typedef long sec_t |
A signed type for expressing seconds.
typedef const unsigned char* trans_bytes |
A transient data bytes pointer.
On input this string must only persist for the duration of the function call. On output this string is valid until another call with the given context is performed and must not be freed.
typedef const char* trans_chars |
A transient NULL terminated string pointer.
On input this string must only persist for the duration of the function call. On output this string is valid until another call with the given context is performed and must not be freed.
typedef const void* trans_ptr |
A transient pointer.
On input this string must only persist for the duration of the function call. On output this string is valid until another call with the given context is performed and must not be freed.
typedef const uint16_t* trans_uni |
A transient UTF16 wchar_t character type.
On input this string must only persist for the duration of the function call. On output this string is valid until another call with the given context is performed and must not be freed.
typedef int64_t usec_t |
A signed type for expressing micro seconds.
RUAPI ptr ruCharPtrDup | ( | char * | in | ) |
Copies the given string and returns the pointer.
in | String to duplicate |
RUAPI trans_chars ruGetenv | ( | trans_chars | variable | ) |
Returns the value of the requested environment vartiable or NULL if it is not set.
variable | Variable name to retrieve |
RUAPI alloc_chars ruGetHostname | ( | void | ) |
Returns the name of this host.
RUAPI alloc_chars ruGetLanguage | ( | void | ) |
Returns the ISO-639-1 2 letter country code pertaining to the running system,.
RUAPI int32_t ruGetOptMap | ( | ruMap * | parms, |
trans_chars | opts, | ||
int | argc, | ||
char ** | argv | ||
) |
Runs getopt short with given parameters.
It does not process non option arguments or permute argv to place these at the end.
parms | Where the string/string map with the parameters will be placed. Caller must free with ruMapFree |
opts | getopt short definition string |
argc | length of argv, as given in main |
argv | array of string parameters with the first being the comman itself as given in main |
RUAPI perm_chars ruGetOs | ( | void | ) |
Returns a lowercase string representation of the current OS.
Currently knows about windows, android, linux, osx, ios and unix.
RUAPI int32_t ruGetTimeVal | ( | ruTimeVal * | result | ) |
RUAPI ruList ruIpAddrs | ( | int32_t | ipfilter | ) |
Returns the IP numbers bound to the host.
RUAPI const char* ruLastError | ( | void | ) |
Returns an English textual representation of the last error this thread generated.
Note, not all functions use this, so this function should only be called after a function that does use it is called, else misleading information will appear.
RUAPI ru_pid ruProcessId | ( | void | ) |
Return the current process id.
RUAPI int32_t ruRunProg | ( | const char ** | argv, |
sec_t | timeout | ||
) |
Runs given program.
Example:
argv | program with params to run |
timeout | Use RU_NON_BLOCK for non blocking, RU_NO_TIMEOUT for blocking and > 0 to a timeout in seconds. |
RUAPI unsigned long ruSemiRandomNumber | ( | unsigned long | max, |
long | offset | ||
) |
Returns a quasi ramdom number between 0 and max + offset.
This function ORs timevals usec with sec, so it is not designed for cryptographic use.
max | The maximum random value. |
offset | An off set to add to the result to move the range. |
RUAPI void ruSleepMs | ( | msec_t | milliseconds | ) |
Sleeps for the given number of milli seconds.
milliseconds |
RUAPI void ruSleepUs | ( | usec_t | microseconds | ) |
Sleeps for the given number of micro seconds.
microseconds |
RUAPI bool ruTimeEllapsed | ( | sec_t | stamp | ) |
Checks if given stamp has elapsed.
stamp | second stamp to compare to. |
RUAPI int ruTimeFormat | ( | trans_chars | format, |
rusize | len, | ||
alloc_chars | timeStr, | ||
sec_t | timesecs | ||
) |
Return the current local time formatted in given buffer.
format | format string for strftime |
len | length of the given buffer must include room for the null terminator |
timeStr | buffer where formatted null terminated string will be placed |
timesecs | datestamp in seconds since epoch or 0 to use current time |
Converts given local time stamp to UTC.
stamp | seconds since epoch in local time |
RUAPI msec_t ruTimeMs | ( | void | ) |
Return the current local time in milliseconds since Jan. 1 1970.
RUAPI bool ruTimeMsEllapsed | ( | msec_t | stamp | ) |
Checks if given stamp has elapsed.
stamp | millisecond stamp to compare to. |
RUAPI sec_t ruTimeParse | ( | trans_chars | dateformat, |
trans_chars | datestr | ||
) |
Convert a string representation of time to a time stamp.
dateformat | a strptime type format string |
datestr | the string representation of the given date time |
RUAPI sec_t ruTimeSec | ( | void | ) |
Return the current local time in seconds since Jan. 1 1970.
RUAPI usec_t ruTimeUs | ( | void | ) |
Return the current local time in microseconds since Jan. 1 1970.
RUAPI bool ruTimeUsEllapsed | ( | usec_t | stamp | ) |
Checks if given stamp has elapsed.
stamp | microsecond stamp to compare to. |
Converts given UTC time stamp to local time.
stamp | UTC seconds since epoch |
RUAPI bool ruTryLoopDone | ( | ruTryLoop * | cycle | ) |
Blocks and returns whether loop is done or not.
cycle | pointer to a ruTryLoop structure |
Handles the details of looping delayed until a timeout is reached. Example:
cycle | pointer to a ruTryLoop structure |
retryMs | how long ruTryLoopDone should block when not done |
timeoutMs | how long ruTryLoopDone should return false after blocking |
RUAPI int ruUtcFormat | ( | trans_chars | format, |
rusize | len, | ||
alloc_chars | timeStr, | ||
sec_t | timesecs | ||
) |
UTC version of ruTimeFormat.
format | format string for strftime |
len | length of the given buffer must include room for the null terminator |
timeStr | buffer where formatted null terminated string will be placed |
timesecs | datestamp in seconds since epoch or 0 to use current time |
RUAPI sec_t ruUtcParse | ( | trans_chars | dateformat, |
trans_chars | datestr | ||
) |
UTC version of ruTimeParse.
dateformat | a strptime type format string |
datestr | the string representation of the given date time |
RUAPI const char* ruVersion | ( | void | ) |
Returns the build version of this package.
RUAPI int ruVersionComp | ( | trans_chars | ver1, |
trans_chars | ver2 | ||
) |
Compares 2 version strings This function compares version number strings that are made up of real numbers. The advantage is that the delimiter does not matter. It will work with, for example, 141.01.03, 141:1:3, or even 141A1P3. It also handles mismatched tails so that 141.1.3 will come before 141.1.3.1. Finally NULLs are also properly compared.
ver1 | First version to check |
ver2 | Second version to check |