39 #ifndef UTIL_REGIFY_UTIL_H
40 #define UTIL_REGIFY_UTIL_H
54 #if defined(regify_util_EXPORTS)
55 #if (defined(WINDOWS) || defined(WIN32) || defined(__BORLANDC__))
57 #define RUAPI extern __declspec(dllexport)
59 #define RUAPI extern __declspec(dllimport)
62 #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
63 #define RUAPI __attribute__ ((visibility ("default")))
73 #if defined(WINDOWS) || defined(WIN32) || defined(__BORLANDC__)
86 typedef long long int64_t;
110 RUAPI int32_t ruGetRegistryEntry(HKEY topKey,
const char* tree,
111 const char* leaf,
char** value);
127 RUAPI int32_t ruGetVolumeInfo(
const char* mountPoint,
128 unsigned long* serialNo,
unsigned long* maxCompLen,
unsigned long* fsFlags,
129 char** volumeName,
char** fsName);
133 #if defined(__APPLE__) && defined(__MACH__)
134 #include <TargetConditionals.h>
135 #if TARGET_OS_IPHONE == 1
139 #elif TARGET_OS_MAC == 1
162 #include <sys/types.h>
309 #ifdef __EMSCRIPTEN__
310 typedef long long sec_t;
349 #define RU_SIZE_AUTO (~0LU)
435 #define RU_NON_BLOCK (-1)
441 #define RU_NO_TIMEOUT 0
562 #define ruSleep(secs) ruSleepMs(((msec_t)(secs))*1000)
650 #define ruMacStart do
651 #define ruMacEnd while(0)
667 #define ruFree(p) ruMacStart { if(p) { free((void*)p); p = NULL; } } ruMacEnd
675 #define ruReplace(p, n) ruMacStart { if(p) { free((void*)p); } p = n; } ruMacEnd
682 #define ruRetWithCode(ptr, code, res) ruMacStart { \
683 if (ptr) { *ptr = code; } return res; \
700 #include <regify-util/errors.h>
701 #include <regify-util/logging.h>
702 #include <regify-util/types.h>
703 #include <regify-util/list.h>
704 #include <regify-util/thread.h>
705 #include <regify-util/string.h>
706 #include <regify-util/map.h>
707 #include <regify-util/cleaner.h>
708 #include <regify-util/ini.h>
709 #include <regify-util/io.h>
710 #include <regify-util/json.h>
711 #include <regify-util/kvstore.h>
712 #include <regify-util/regex.h>
713 #include <regify-util/html.h>
714 #if !defined(__ANDROID__) && defined(__linux__) || defined(ITS_OSX) || defined(_WIN32)
715 #include <regify-util/fam.h>
722 #if !defined(__ANDROID__)
738 #define RU_IP (RU_IP4 | RU_IP6)
788 RUAPI int32_t ruGetOptMapW(
ruMap* parms,
trans_chars opts, DWORD wargc, LPWSTR* wargv);
812 #define ruMalloc0(count, ctype) (ctype*) ruMallocSize((rusize)(count), sizeof(ctype));
832 #define ruRealloc(buf, count, ctype) (ctype*) ruReallocSize(buf, count, sizeof(ctype))
853 #define ruMakeTypeGetter(ctype, magic) \
854 ctype* ctype ## Get(void* ptr, int32_t* code) { \
855 ctype* ret = (ctype*) ptr; \
857 ruRetWithCode(code, RUE_PARAMETER_NOT_SET, NULL); \
859 if (ptr < (void*)0xffff || magic != ret->type) { \
860 ruRetWithCode(code, RUE_INVALID_PARAMETER, NULL); \
862 ruRetWithCode(code, RUE_OK, ret); \
865 #define ruZeroedStruct(type, var) type var; \
866 memset(&(var), 0, sizeof(type))
868 #define ruMakeTypeGetHeader(ctype) \
869 ctype* ctype ## Get(void* ptr, int32_t* code)
877 #include <regify-util/logging.h>
void * ruCleaner
Definition: regify-util.h:690
void * ruMap
An opaque type representing a map object.
Definition: map.h:33
void * ruList
Opaque pointer to list object. See List Collection.
Definition: list.h:103
ptr(* ruClearFunc)(ptr o)
Signature of a generic free function returning NULL.
Definition: regify-util.h:356
RUAPI ptr ruClear(ptr o)
Frees given resource if set and returns NULL.
RUAPI alloc_ptr ruMemDup(trans_ptr buf, rusize size)
Returns a copy of the given memory block.
RUAPI alloc_ptr ruReallocSize(alloc_ptr buf, rusize count, rusize ofsize)
Reallocate requested memory without zeroing.
RUAPI alloc_ptr ruMallocSize(rusize count, rusize ofsize)
Allocate and zero requested memory.
void(* ruFreeFunc)(ptr o)
Signature of a generic free function.
Definition: regify-util.h:363
int64_t usec_t
A signed type for expressing micro seconds.
Definition: regify-util.h:323
RUAPI msec_t ruTimeMs(void)
Return the current local time in milliseconds since Jan. 1 1970.
intptr_t ru_int
A pointer sized integer type for collections like ruMap or ruList.
Definition: regify-util.h:328
const void * trans_ptr
A transient pointer.
Definition: regify-util.h:287
RUAPI void ruTryLoopInit(ruTryLoop *cycle, msec_t retryMs, msec_t timeoutMs)
RUAPI int32_t ruGetTimeVal(ruTimeVal *result)
Returns a ruTimeVal representing the current time.
unsigned char * alloc_bytes
An allocated data bytes pointer.
Definition: regify-util.h:267
RUAPI alloc_chars ruGetLanguage(void)
Returns the ISO-639-1 2 letter country code pertaining to the running system,.
uint16_t * alloc_uni
An allocated UTF16 wchar_t character type.
Definition: regify-util.h:233
RUAPI sec_t ruTimeUtcToLocal(sec_t stamp)
Converts given UTC time stamp to local time.
RUAPI void ruSleepUs(usec_t microseconds)
Sleeps for the given number of micro seconds.
const void * perm_ptr
A permanent pointer.
Definition: regify-util.h:277
RUAPI int ruTimeFormat(trans_chars format, rusize len, alloc_chars timeStr, sec_t timesecs)
Return the current local time formatted in given buffer.
const uint16_t * trans_uni
A transient UTF16 wchar_t character type.
Definition: regify-util.h:220
const char * trans_chars
A transient NULL terminated string pointer.
Definition: regify-util.h:186
RUAPI sec_t ruTimeSec(void)
Return the current local time in seconds since Jan. 1 1970.
RUAPI sec_t ruTimeParse(trans_chars dateformat, trans_chars datestr)
Convert a string representation of time to a time stamp.
uintptr_t ru_uint
A pointer sized unsigned integer type for collections like ruMap or ruList.
Definition: regify-util.h:333
pid_t ru_pid
Abstracted process id type.
Definition: regify-util.h:163
RUAPI sec_t ruTimeLocalToUtc(sec_t stamp)
Converts given local time stamp to UTC.
RUAPI int32_t ruGetOptMap(ruMap *parms, trans_chars opts, int argc, char **argv)
Runs getopt short with given parameters.
RUAPI const char * ruVersion(void)
Returns the build version of this package.
const char * perm_chars
A permanent NULL terminated string pointer.
Definition: regify-util.h:176
RUAPI bool ruTimeMsEllapsed(msec_t stamp)
Checks if given stamp has elapsed.
long sec_t
A signed type for expressing seconds.
Definition: regify-util.h:312
const uint16_t * perm_uni
A permanent UTF16 wchar_t character type.
Definition: regify-util.h:210
RUAPI perm_chars ruGetOs(void)
Returns a lowercase string representation of the current OS.
RUAPI bool ruTryLoopDone(ruTryLoop *cycle)
char * alloc_chars
An allocated NULL terminated string pointer.
Definition: regify-util.h:199
void * alloc_ptr
An allocated pointer.
Definition: regify-util.h:299
RUAPI int32_t ruRunProg(const char **argv, sec_t timeout)
Runs given program.
size_t rusize
Abstracted version of size_t.
Definition: regify-util.h:338
const unsigned char * perm_bytes
A permanent data bytes pointer.
Definition: regify-util.h:244
RUAPI alloc_chars ruGetHostname(void)
Returns the name of this host.
void * ptr
A generic pointer.
Definition: regify-util.h:304
const unsigned char * trans_bytes
A transient data bytes pointer.
Definition: regify-util.h:254
RUAPI sec_t ruUtcParse(trans_chars dateformat, trans_chars datestr)
UTC version of ruTimeParse.
RUAPI ptr ruCharPtrDup(char *in)
Copies the given string and returns the pointer.
signed long rusize_s
Abstracted version of size_t but signed.
Definition: regify-util.h:152
RUAPI ruList ruIpAddrs(int32_t ipfilter)
Returns the IP numbers bound to the host.
RUAPI bool ruTimeEllapsed(sec_t stamp)
Checks if given stamp has elapsed.
RUAPI bool ruTimeUsEllapsed(usec_t stamp)
Checks if given stamp has elapsed.
RUAPI trans_chars ruGetenv(trans_chars variable)
Returns the value of the requested environment vartiable or NULL if it is not set.
RUAPI void ruSleepMs(msec_t milliseconds)
Sleeps for the given number of milli seconds.
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 num...
int64_t msec_t
A signed type for expressing milli seconds.
Definition: regify-util.h:318
RUAPI usec_t ruTimeUs(void)
Return the current local time in microseconds since Jan. 1 1970.
RUAPI const char * ruLastError(void)
Returns an English textual representation of the last error this thread generated.
RUAPI int ruUtcFormat(trans_chars format, rusize len, alloc_chars timeStr, sec_t timesecs)
UTC version of ruTimeFormat.
RUAPI unsigned long ruSemiRandomNumber(unsigned long max, long offset)
Returns a quasi ramdom number between 0 and max + offset.
RUAPI ru_pid ruProcessId(void)
Return the current process id.
void * ruType
An opaque type representing a type specification.
Definition: regify-util.h:344
Abstracted version of the Posix struct timeval.
Definition: regify-util.h:368
sec_t sec
Definition: regify-util.h:369
usec_t usec
Definition: regify-util.h:370
Definition: regify-util.h:374
msec_t finish
Definition: regify-util.h:376
msec_t start
Definition: regify-util.h:375
msec_t retry
Definition: regify-util.h:377