Nilorea Library
C utilities for networking, threading, graphics
|
Macros | |
#define | __EXTENSIONS__ |
feature test macro More... | |
#define | __n_assert(__ptr, __ret) |
macro to assert things More... | |
#define | _nstr(__PTR) ((__PTR&&__PTR->data)?(__PTR->data):"NULL") |
N_STR or "NULL" string for logging purposes. More... | |
#define | _nstrp(__PTR) ((__PTR&&__PTR->data)?(__PTR->data):NULL) |
N_STR or NULL pointer for testing purposes. More... | |
#define | _str(__PTR) ((__PTR)?(__PTR):"NULL") |
define true More... | |
#define | _strp(__PTR) ((__PTR)?(__PTR):NULL) |
String or NULL pointer for testing purposes. More... | |
#define | _strw(__PTR) ((__PTR)?(__PTR):" ") |
String or " " string for config purposes. More... | |
#define | Alloca(__ptr, __size) |
Malloca Handler to get errors and set to 0. More... | |
#define | BYTEORDER_BIG_ENDIAN 1 |
Big endian macro value. More... | |
#define | BYTEORDER_LITTLE_ENDIAN 0 |
Little endian macro value. More... | |
#define | CALL_RETRY(retvar, expression) |
TEMP_FAILURE gnu macro portable version. More... | |
#define | checkerror() |
check for errors More... | |
#define | CONCAT(a, b) CONCAT_BUILDER(a, b) |
Concatenate two macro. More... | |
#define | CONCAT_BUILDER(a, b) a ## b |
CONCAT macro helper. More... | |
#define | DEFAULT 1000 |
Default APP_STATUS Value. More... | |
#define | endif ){ ___error__check_flag = TRUE ; n_log( LOG_ERR , "First err was at line %d of %s" , __LINE__ , __FILE__ );} |
close a ifwhatever block More... | |
#define | equal_if(__a, __cond, __b) if( (__a) __cond (__b) ){ __a = __b ; } |
if( a , condition, b ) then a = b More... | |
#define | FALL_THROUGH |
set windows if true More... | |
#define | FORCE_INLINE __attribute__((always_inline)) |
FORCE_INLINE portable macro. More... | |
#define | Free(__ptr) |
Free Handler to get errors. More... | |
#define | FreeNoLog(__ptr) |
Free Handler without log. More... | |
#define | GET 4321 |
Flag for GET something , passing as a function parameter. More... | |
#define | get_error() (___error__check_flag == TRUE) |
pop up errors if any More... | |
#define | htonll(x) (x) |
htonl for 64 bits numbers More... | |
#define | iffalse if( FALSE == |
error checker type if( toto == FALSE ) More... | |
#define | ifnull if( ! |
error checker type if( !toto ) More... | |
#define | iftrue if( TRUE == |
error checker type if( toto == FALSE ) More... | |
#define | ifzero if( 0 == |
error checker type if( 0 != toto ) More... | |
#define | init_error_check() static int ___error__check_flag = FALSE ; |
init error checking in a function More... | |
#define | init_lock(__rwlock_mutex) |
Macro for initializing a rwlock. More... | |
#define | Malloc(__ptr, __struct, __size) |
Malloc Handler to get errors and set to 0. More... | |
#define | next_even(__val) ( (__val)%2 == 0 ) ? (__val + 1) : ( __val ) |
next odd helper More... | |
#define | next_odd(__val) ( (__val)%2 == 0 ) ? (__val) : ( __val + 1 ) |
next odd helper More... | |
#define | ntohll(x) (x) |
ntonl for 64 bits numbers More... | |
#define | PAUSED 1004 |
Value of the state of an application who is paused. More... | |
#define | randomize() { srand((unsigned)time(NULL)); rand(); } |
Initialize the random sequence with time. More... | |
#define | read_lock(__rwlock_mutex) |
Macro for acquiring a read lock on a rwlock mutex. More... | |
#define | Realloc(__ptr, __struct, __size) |
Realloc Handler to get errors. More... | |
#define | Reallocz(__ptr, __struct, __old_size, __size) |
Realloc + zero new memory zone Handler to get errors. More... | |
#define | RUNNING 1001 |
Value of the state of an application who is running. More... | |
#define | rw_lock_destroy(__rwlock_mutex) |
Macro to destroy rwlock mutex. More... | |
#define | RWLOCK_LOGLEVEL LOG_NULL |
flag to tell the API to disable DEBUG log on locks More... | |
#define | SET 1234 |
Flag for SET something , passing as a function parameter. More... | |
#define | STOPPED 1003 |
Value of the state of an application who is stopped. More... | |
#define | STOPWANTED 1002 |
Value of the state of an application who want to stop his activity. More... | |
#define | unlock(__rwlock_mutex) |
Macro for releasing read/write lock a rwlock mutex. More... | |
#define | write_lock(__rwlock_mutex) |
Macro for acquiring a write lock on a rwlock mutex. More... | |
Functions | |
int | file_exist (const char *filename) |
test if file exist and if it's readable More... | |
int | get_computer_name (char *computer_name, size_t len) |
abort program with a text More... | |
char * | get_prog_dir (void) |
get current program running directory More... | |
char * | get_prog_name (void) |
get current program name More... | |
void | n_abort (char const *format,...) |
abort program with a text More... | |
int | n_daemonize (void) |
Daemonize program. More... | |
char * | n_get_file_extension (char path[]) |
get extension of path+filename More... | |
void | N_HIDE_STR (char *buf,...) |
store a hidden version of a string More... | |
int | n_popen (char *cmd, int read_buf_size, void **nstr_output, int *ret) |
launch a command abd return output and status More... | |
pid_t | system_nb (const char *command, int *infp, int *outfp) |
Non blocking system call. More... | |
#define __EXTENSIONS__ |
feature test macro
Definition at line 32 of file n_common.h.
#define __n_assert | ( | __ptr, | |
__ret | |||
) |
macro to assert things
Definition at line 276 of file n_common.h.
#define _nstr | ( | __PTR | ) | ((__PTR&&__PTR->data)?(__PTR->data):"NULL") |
N_STR or "NULL" string for logging purposes.
Definition at line 178 of file n_common.h.
#define _nstrp | ( | __PTR | ) | ((__PTR&&__PTR->data)?(__PTR->data):NULL) |
N_STR or NULL pointer for testing purposes.
Definition at line 180 of file n_common.h.
#define _str | ( | __PTR | ) | ((__PTR)?(__PTR):"NULL") |
define true
define TRUE
define false
define FALSE
returned by N_STRLIST functions to tell the caller that the list is empty
String or "NULL" string for logging purposes
Definition at line 172 of file n_common.h.
#define _strp | ( | __PTR | ) | ((__PTR)?(__PTR):NULL) |
String or NULL pointer for testing purposes.
Definition at line 174 of file n_common.h.
#define _strw | ( | __PTR | ) | ((__PTR)?(__PTR):" ") |
String or " " string for config purposes.
Definition at line 176 of file n_common.h.
#define Alloca | ( | __ptr, | |
__size | |||
) |
Malloca Handler to get errors and set to 0.
Definition at line 198 of file n_common.h.
#define BYTEORDER_BIG_ENDIAN 1 |
Big endian macro value.
Definition at line 77 of file n_common.h.
#define BYTEORDER_LITTLE_ENDIAN 0 |
Little endian macro value.
Definition at line 75 of file n_common.h.
#define CALL_RETRY | ( | retvar, | |
expression | |||
) |
TEMP_FAILURE gnu macro portable version.
Definition at line 284 of file n_common.h.
#define checkerror | ( | ) |
check for errors
Definition at line 312 of file n_common.h.
#define CONCAT | ( | a, | |
b | |||
) | CONCAT_BUILDER(a, b) |
Concatenate two macro.
Definition at line 450 of file n_common.h.
#define CONCAT_BUILDER | ( | a, | |
b | |||
) | a ## b |
CONCAT macro helper.
Definition at line 448 of file n_common.h.
#define DEFAULT 1000 |
Default APP_STATUS Value.
Definition at line 424 of file n_common.h.
#define equal_if | ( | __a, | |
__cond, | |||
__b | |||
) | if( (__a) __cond (__b) ){ __a = __b ; } |
if( a , condition, b ) then a = b
Definition at line 325 of file n_common.h.
#define FALL_THROUGH |
#define FORCE_INLINE __attribute__((always_inline)) |
#define Free | ( | __ptr | ) |
Free Handler to get errors.
Definition at line 256 of file n_common.h.
#define FreeNoLog | ( | __ptr | ) |
Free Handler without log.
Definition at line 268 of file n_common.h.
#define GET 4321 |
Flag for GET something , passing as a function parameter.
Definition at line 422 of file n_common.h.
#define get_error | ( | ) | (___error__check_flag == TRUE) |
#define htonll | ( | x | ) | (x) |
htonl for 64 bits numbers
Definition at line 454 of file n_common.h.
#define iffalse if( FALSE == |
error checker type if( toto == FALSE )
Definition at line 306 of file n_common.h.
#define ifnull if( ! |
#define iftrue if( TRUE == |
error checker type if( toto == FALSE )
Definition at line 309 of file n_common.h.
#define ifzero if( 0 == |
#define init_error_check | ( | ) | static int ___error__check_flag = FALSE ; |
#define init_lock | ( | __rwlock_mutex | ) |
Macro for initializing a rwlock.
Definition at line 337 of file n_common.h.
#define Malloc | ( | __ptr, | |
__struct, | |||
__size | |||
) |
Malloc Handler to get errors and set to 0.
Definition at line 183 of file n_common.h.
#define next_even | ( | __val | ) | ( (__val)%2 == 0 ) ? (__val + 1) : ( __val ) |
#define next_odd | ( | __val | ) | ( (__val)%2 == 0 ) ? (__val) : ( __val + 1 ) |
#define ntohll | ( | x | ) | (x) |
ntonl for 64 bits numbers
Definition at line 456 of file n_common.h.
#define PAUSED 1004 |
Value of the state of an application who is paused.
Definition at line 432 of file n_common.h.
#define randomize | ( | ) | { srand((unsigned)time(NULL)); rand(); } |
Initialize the random sequence with time.
Definition at line 435 of file n_common.h.
#define read_lock | ( | __rwlock_mutex | ) |
Macro for acquiring a read lock on a rwlock mutex.
Definition at line 357 of file n_common.h.
#define Realloc | ( | __ptr, | |
__struct, | |||
__size | |||
) |
Realloc Handler to get errors.
Definition at line 217 of file n_common.h.
#define Reallocz | ( | __ptr, | |
__struct, | |||
__old_size, | |||
__size | |||
) |
Realloc + zero new memory zone Handler to get errors.
Definition at line 236 of file n_common.h.
#define RUNNING 1001 |
Value of the state of an application who is running.
Definition at line 426 of file n_common.h.
#define rw_lock_destroy | ( | __rwlock_mutex | ) |
Macro to destroy rwlock mutex.
Definition at line 404 of file n_common.h.
#define RWLOCK_LOGLEVEL LOG_NULL |
flag to tell the API to disable DEBUG log on locks
Definition at line 333 of file n_common.h.
#define SET 1234 |
Flag for SET something , passing as a function parameter.
Definition at line 420 of file n_common.h.
#define STOPPED 1003 |
Value of the state of an application who is stopped.
Definition at line 430 of file n_common.h.
#define STOPWANTED 1002 |
Value of the state of an application who want to stop his activity.
Definition at line 428 of file n_common.h.
#define unlock | ( | __rwlock_mutex | ) |
Macro for releasing read/write lock a rwlock mutex.
Definition at line 389 of file n_common.h.
#define write_lock | ( | __rwlock_mutex | ) |
Macro for acquiring a write lock on a rwlock mutex.
Definition at line 373 of file n_common.h.
int file_exist | ( | const char * | filename | ) |
test if file exist and if it's readable
filename | Path/name of the file |
Definition at line 92 of file n_common.c.
int get_computer_name | ( | char * | computer_name, |
size_t | len | ||
) |
abort program with a text
computer_name | allocated buffer to hold the computer name |
len | size of computer_name variable |
Definition at line 58 of file n_common.c.
References LOG_ERR, and n_log.
Referenced by n_kafka_load_config().
char * get_prog_dir | ( | void | ) |
get current program running directory
Definition at line 109 of file n_common.c.
char * get_prog_name | ( | void | ) |
get current program name
Definition at line 145 of file n_common.c.
void n_abort | ( | char const * | format, |
... | |||
) |
abort program with a text
format | printf style format and args |
Definition at line 38 of file n_common.c.
int n_daemonize | ( | void | ) |
Daemonize program.
Definition at line 236 of file n_common.c.
References LOG_ERR, LOG_NOTICE, and n_log.
char * n_get_file_extension | ( | char | path[] | ) |
get extension of path+filename
path | the path + filename |
Definition at line 394 of file n_common.c.
References __n_assert.
void N_HIDE_STR | ( | char * | buf, |
... | |||
) |
store a hidden version of a string
buf | the variable which will receive the string |
Definition at line 371 of file n_common.c.
int n_popen | ( | char * | cmd, |
int | read_buf_size, | ||
void ** | nstr_output, | ||
int * | ret | ||
) |
launch a command abd return output and status
cmd | The command to launch |
read_buf_size | popen read buf. Also serves as a minimum size for the dynamically allocated returned output if not already allocaded |
nstr_output | Pointer to a valid N_STR or NULL (see read_buf_size) |
ret | Command output if any. Should be initialized to -1 and tested against to check if it's valid. |
Definition at line 185 of file n_common.c.
References __n_assert, LOG_ERR, n_log, new_nstr(), and nstrprintf_cat.
Referenced by addr2line(), and n_get_current_dir_hd_serial().
pid_t system_nb | ( | const char * | command, |
int * | infp, | ||
int * | outfp | ||
) |
Non blocking system call.
command | to call |
infp | stdin file descriptor holder or NULL |
outfp | stdout file descriptor holder or NULL |
Close all other descriptors for the safety sake.
Definition at line 293 of file n_common.c.
References __n_assert, LOG_ERR, and n_log.