![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Macros | |
| #define | __n_assert(__ptr, __ret) |
| macro to assert things | |
| #define | _nstr(__PTR) ((__PTR && __PTR->data) ? (__PTR->data) : "NULL") |
| N_STR or "NULL" string for logging purposes. | |
| #define | _nstrp(__PTR) ((__PTR && __PTR->data) ? (__PTR->data) : NULL) |
| N_STR or NULL pointer for testing purposes. | |
| #define | _str(__PTR) ((__PTR) ? (__PTR) : "NULL") |
| define true | |
| #define | _strp(__PTR) ((__PTR) ? (__PTR) : NULL) |
| String or NULL pointer for testing purposes. | |
| #define | _strw(__PTR) ((__PTR) ? (__PTR) : " ") |
| String or " " string for config purposes. | |
| #define | Alloca(__ptr, __size) |
| Malloca Handler to get errors and set to 0. | |
| #define | BYTEORDER_BIG_ENDIAN 1 |
| Big endian macro value. | |
| #define | BYTEORDER_LITTLE_ENDIAN 0 |
| Little endian macro value. | |
| #define | CALL_RETRY(__retvar, __expression, __max_tries) |
| TEMP_FAILURE gnu macro portable version. | |
| #define | checkerror() |
| check for errors | |
| #define | CONCAT(a, b) CONCAT_BUILDER(a, b) |
| Concatenate two macro. | |
| #define | CONCAT_BUILDER(a, b) a##b |
| CONCAT macro helper. | |
| #define | DEFAULT 1000 |
| Default APP_STATUS Value. | |
| #define | endif |
| close a ifwhatever block | |
| #define | equal_if(__a, __cond, __b) |
| if( a , condition, b ) then a = b | |
| #define | FALL_THROUGH |
| set windows if true | |
| #define | FORCE_INLINE static inline __attribute__((always_inline)) |
| FORCE_INLINE portable macro. | |
| #define | Free(__ptr) |
| Free Handler to get errors. | |
| #define | FreeNoLog(__ptr) |
| Free Handler without log. | |
| #define | GET 4321 |
| Flag for GET something , passing as a function parameter. | |
| #define | get_error() (___error__check_flag == TRUE) |
| pop up errors if any | |
| #define | iffalse if( FALSE == |
| error checker type if( toto == FALSE ) | |
| #define | ifnull if( ! |
| error checker type if( !toto ) | |
| #define | iftrue if( TRUE == |
| error checker type if( toto == FALSE ) | |
| #define | ifzero if( 0 == |
| error checker type if( 0 != toto ) | |
| #define | init_error_check() static int ___error__check_flag = FALSE; |
| init error checking in a function | |
| #define | init_lock(__rwlock_mutex) |
| Macro for initializing a rwlock. | |
| #define | Malloc(__ptr, __struct, __size) |
| Malloc Handler to get errors and set to 0. | |
| #define | N_DAEMON_NO_CHDIR 64 |
| daemonize flag: do not call chdir("/") | |
| #define | N_DAEMON_NO_CLOSE 2 |
| daemonize flag: no descriptor close at all | |
| #define | N_DAEMON_NO_DOUBLE_FORK 8 |
| daemonize flag: do not double fork | |
| #define | N_DAEMON_NO_SETSID 16 |
| daemonize flag: do not call setsid | |
| #define | N_DAEMON_NO_SIGCHLD_HANDLER 256 |
| daemonize flag: do not use internal zombie SIGCHLD handler | |
| #define | N_DAEMON_NO_SIGCHLD_IGN 128 |
| daemonize flag: do not ignore SIGCHLD | |
| #define | N_DAEMON_NO_STD_REDIRECT 4 |
| daemonize flag: just do not redirect stdin/out/err to /dev/null | |
| #define | N_DAEMON_NO_UMASK 32 |
| daemonize flag: do not call umask( 0 ) | |
| #define | next_even(__val) (((__val) % 2 == 0) ? (__val) : ((__val) + 1)) |
| next even helper | |
| #define | next_odd(__val) (((__val) % 2 == 0) ? ((__val) + 1) : (__val)) |
| next odd helper | |
| #define | PAUSED 1004 |
| Value of the state of an application who is paused. | |
| #define | randomize() |
| Initialize the random sequence with time. | |
| #define | read_lock(__rwlock_mutex) |
| Macro for acquiring a read lock on a rwlock mutex. | |
| #define | Realloc(__ptr, __struct, __size) |
| Realloc Handler to get errors. | |
| #define | Reallocz(__ptr, __struct, __old_size, __size) |
| Realloc + zero new memory zone Handler to get errors. | |
| #define | RUNNING 1001 |
| Value of the state of an application who is running. | |
| #define | rw_lock_destroy(__rwlock_mutex) |
| Macro to destroy rwlock mutex. | |
| #define | RWLOCK_LOGLEVEL LOG_NULL |
| flag to tell the API to disable DEBUG log on locks | |
| #define | SET 1234 |
| Flag for SET something , passing as a function parameter. | |
| #define | STOPPED 1003 |
| Value of the state of an application who is stopped. | |
| #define | STOPWANTED 1002 |
| Value of the state of an application who want to stop his activity. | |
| #define | unlock(__rwlock_mutex) |
| Macro for releasing read/write lock a rwlock mutex. | |
| #define | write_lock(__rwlock_mutex) |
| Macro for acquiring a write lock on a rwlock mutex. | |
Functions | |
| int | file_exist (const char *filename) |
| test file presence | |
| int | get_computer_name (char *computer_name, size_t len) |
| get the computer name into the given buffer | |
| char * | get_prog_dir (void) |
| get running program directory | |
| char * | get_prog_name (void) |
| get running program name | |
| void | log_environment (int loglevel) |
| log environment variables at the given log level | |
| void | n_abort (char const *format,...) |
| htonl for 64 bits numbers | |
| int | n_daemonize (void) |
| daemonize the current process | |
| int | n_daemonize_ex (int mode) |
| daemonize the current process with the given mode flags | |
| char * | n_get_file_extension (char path[]) |
| get the file extension from a path | |
| void | N_HIDE_STR (char *buf,...) |
| reconstruct hidden string from variadic char arguments | |
| int | n_popen (char *cmd, size_t read_buf_size, void **nstr_output, int *ret) |
| shortcut for popen usage | |
| void | sigchld_handler (int sig) |
| reap zombie processes | |
| int | sigchld_handler_installer () |
| install signal SIGCHLD handler | |
| pid_t | system_nb (const char *command, int *infp, int *outfp) |
| non-blocking system call | |
| #define __n_assert | ( | __ptr, | |
| __ret | |||
| ) |
macro to assert things
Definition at line 278 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 198 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 200 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 192 of file n_common.h.
| #define _strp | ( | __PTR | ) | ((__PTR) ? (__PTR) : NULL) |
String or NULL pointer for testing purposes.
Definition at line 194 of file n_common.h.
| #define _strw | ( | __PTR | ) | ((__PTR) ? (__PTR) : " ") |
String or " " string for config purposes.
Definition at line 196 of file n_common.h.
| #define Alloca | ( | __ptr, | |
| __size | |||
| ) |
Malloca Handler to get errors and set to 0.
Definition at line 215 of file n_common.h.
| #define BYTEORDER_BIG_ENDIAN 1 |
Big endian macro value.
Definition at line 100 of file n_common.h.
| #define BYTEORDER_LITTLE_ENDIAN 0 |
Little endian macro value.
Definition at line 98 of file n_common.h.
| #define CALL_RETRY | ( | __retvar, | |
| __expression, | |||
| __max_tries | |||
| ) |
TEMP_FAILURE gnu macro portable version.
Definition at line 285 of file n_common.h.
| #define checkerror | ( | ) |
check for errors
Definition at line 317 of file n_common.h.
| #define CONCAT | ( | a, | |
| b | |||
| ) | CONCAT_BUILDER(a, b) |
Concatenate two macro.
Definition at line 455 of file n_common.h.
| #define CONCAT_BUILDER | ( | a, | |
| b | |||
| ) | a##b |
CONCAT macro helper.
Definition at line 453 of file n_common.h.
| #define DEFAULT 1000 |
Default APP_STATUS Value.
Definition at line 426 of file n_common.h.
| #define endif |
close a ifwhatever block
Definition at line 324 of file n_common.h.
| #define equal_if | ( | __a, | |
| __cond, | |||
| __b | |||
| ) |
if( a , condition, b ) then a = b
Definition at line 334 of file n_common.h.
| #define FALL_THROUGH |
set windows if true
fall through macro for switch cases, avoid warning at compilation
Definition at line 71 of file n_common.h.
| #define FORCE_INLINE static inline __attribute__((always_inline)) |
FORCE_INLINE portable macro.
Definition at line 163 of file n_common.h.
| #define Free | ( | __ptr | ) |
Free Handler to get errors.
Definition at line 262 of file n_common.h.
| #define FreeNoLog | ( | __ptr | ) |
Free Handler without log.
Definition at line 271 of file n_common.h.
| #define GET 4321 |
Flag for GET something , passing as a function parameter.
Definition at line 424 of file n_common.h.
| #define get_error | ( | ) | (___error__check_flag == TRUE) |
| #define iffalse if( FALSE == |
error checker type if( toto == FALSE )
Definition at line 311 of file n_common.h.
| #define ifnull if( ! |
error checker type if( !toto )
Definition at line 305 of file n_common.h.
| #define iftrue if( TRUE == |
error checker type if( toto == FALSE )
Definition at line 314 of file n_common.h.
| #define ifzero if( 0 == |
error checker type if( 0 != toto )
Definition at line 308 of file n_common.h.
| #define init_error_check | ( | ) | static int ___error__check_flag = FALSE; |
init error checking in a function
Definition at line 301 of file n_common.h.
| #define init_lock | ( | __rwlock_mutex | ) |
Macro for initializing a rwlock.
Definition at line 349 of file n_common.h.
| #define Malloc | ( | __ptr, | |
| __struct, | |||
| __size | |||
| ) |
Malloc Handler to get errors and set to 0.
Definition at line 203 of file n_common.h.
| #define N_DAEMON_NO_CHDIR 64 |
daemonize flag: do not call chdir("/")
Definition at line 514 of file n_common.h.
| #define N_DAEMON_NO_CLOSE 2 |
daemonize flag: no descriptor close at all
Definition at line 504 of file n_common.h.
| #define N_DAEMON_NO_DOUBLE_FORK 8 |
daemonize flag: do not double fork
Definition at line 508 of file n_common.h.
| #define N_DAEMON_NO_SETSID 16 |
daemonize flag: do not call setsid
Definition at line 510 of file n_common.h.
| #define N_DAEMON_NO_SIGCHLD_HANDLER 256 |
daemonize flag: do not use internal zombie SIGCHLD handler
Definition at line 518 of file n_common.h.
| #define N_DAEMON_NO_SIGCHLD_IGN 128 |
daemonize flag: do not ignore SIGCHLD
Definition at line 516 of file n_common.h.
| #define N_DAEMON_NO_STD_REDIRECT 4 |
daemonize flag: just do not redirect stdin/out/err to /dev/null
Definition at line 506 of file n_common.h.
| #define N_DAEMON_NO_UMASK 32 |
daemonize flag: do not call umask( 0 )
Definition at line 512 of file n_common.h.
| #define next_even | ( | __val | ) | (((__val) % 2 == 0) ? (__val) : ((__val) + 1)) |
| #define next_odd | ( | __val | ) | (((__val) % 2 == 0) ? ((__val) + 1) : (__val)) |
| #define PAUSED 1004 |
Value of the state of an application who is paused.
Definition at line 434 of file n_common.h.
| #define randomize | ( | ) |
Initialize the random sequence with time.
Definition at line 437 of file n_common.h.
| #define read_lock | ( | __rwlock_mutex | ) |
Macro for acquiring a read lock on a rwlock mutex.
Definition at line 367 of file n_common.h.
| #define Realloc | ( | __ptr, | |
| __struct, | |||
| __size | |||
| ) |
Realloc Handler to get errors.
Returns TRUE on success, FALSE on failure. On failure the original pointer is preserved (not set to NULL).
Definition at line 230 of file n_common.h.
| #define Reallocz | ( | __ptr, | |
| __struct, | |||
| __old_size, | |||
| __size | |||
| ) |
Realloc + zero new memory zone Handler to get errors.
Returns TRUE on success, FALSE on failure. On failure the original pointer is preserved (not set to NULL).
Definition at line 246 of file n_common.h.
| #define RUNNING 1001 |
Value of the state of an application who is running.
Definition at line 428 of file n_common.h.
| #define rw_lock_destroy | ( | __rwlock_mutex | ) |
Macro to destroy rwlock mutex.
Definition at line 408 of file n_common.h.
| #define RWLOCK_LOGLEVEL LOG_NULL |
flag to tell the API to disable DEBUG log on locks
Definition at line 345 of file n_common.h.
| #define SET 1234 |
Flag for SET something , passing as a function parameter.
Definition at line 422 of file n_common.h.
| #define STOPPED 1003 |
Value of the state of an application who is stopped.
Definition at line 432 of file n_common.h.
| #define STOPWANTED 1002 |
Value of the state of an application who want to stop his activity.
Definition at line 430 of file n_common.h.
| #define unlock | ( | __rwlock_mutex | ) |
Macro for releasing read/write lock a rwlock mutex.
Definition at line 395 of file n_common.h.
| #define write_lock | ( | __rwlock_mutex | ) |
Macro for acquiring a write lock on a rwlock mutex.
Definition at line 381 of file n_common.h.
| int file_exist | ( | const char * | filename | ) |
test file presence
test file presence
| filename | Path/name of the file |
Definition at line 99 of file n_common.c.
Referenced by main().
Here is the caller graph for this function:| int get_computer_name | ( | char * | computer_name, |
| size_t | len | ||
| ) |
get the computer name into the given buffer
get the computer name into the given buffer
| computer_name | allocated buffer to hold the computer name |
| len | size of computer_name variable |
Definition at line 69 of file n_common.c.
References LOG_ERR, and n_log.
Referenced by main(), and n_kafka_load_config().
Here is the caller graph for this function:| char * get_prog_dir | ( | void | ) |
get running program directory
get running program directory
Definition at line 112 of file n_common.c.
Referenced by main().
Here is the caller graph for this function:| char * get_prog_name | ( | void | ) |
get running program name
get running program name
Definition at line 144 of file n_common.c.
Referenced by main().
Here is the caller graph for this function:| void log_environment | ( | int | loglevel | ) |
log environment variables at the given log level
log environment variables at the given log level
| loglevel | the loglevel used to log the environment |
Definition at line 231 of file n_common.c.
References n_log.
Referenced by main().
Here is the caller graph for this function:| void n_abort | ( | char const * | format, |
| ... | |||
| ) |
htonl for 64 bits numbers
ntonl for 64 bits numbers
exit and print log to stderr
htonl for 64 bits numbers
| format | printf style format and args |
Definition at line 52 of file n_common.c.
Referenced by main(), and main().
Here is the caller graph for this function:| int n_daemonize | ( | void | ) |
daemonize the current process
daemonize the current process
Definition at line 283 of file n_common.c.
References N_DAEMON_NO_SIGCHLD_HANDLER, N_DAEMON_NO_SIGCHLD_IGN, and n_daemonize_ex().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int n_daemonize_ex | ( | int | mode | ) |
daemonize the current process with the given mode flags
daemonize the current process with the given mode flags
| mode | flag made of a combination of N_DAEMON_NO_CLOSE, N_DAEMON_NO_STD_REDIRECT, N_DAEMON_NO_DOUBLE_FORK , N_DAEMON_NO_SETSID, N_DAEMON_NO_UMASK, N_DAEMON_NO_CHDIR, N_DAEMON_NO_SETSID, N_DAEMON_NO_SIGCHLD_IGN, N_DAEMON_NO_SIGCHLD_HANDLER or 0 for defaults |
Definition at line 292 of file n_common.c.
References LOG_ERR, LOG_NOTICE, mode, N_DAEMON_NO_CHDIR, N_DAEMON_NO_CLOSE, N_DAEMON_NO_DOUBLE_FORK, N_DAEMON_NO_SETSID, N_DAEMON_NO_SIGCHLD_HANDLER, N_DAEMON_NO_SIGCHLD_IGN, N_DAEMON_NO_STD_REDIRECT, N_DAEMON_NO_UMASK, n_log, and sigchld_handler_installer().
Referenced by n_daemonize().
Here is the call graph for this function:
Here is the caller graph for this function:| char * n_get_file_extension | ( | char | path[] | ) |
get the file extension from a path
get the file extension from a path
| path | the path + filename |
Definition at line 479 of file n_common.c.
References __n_assert.
Referenced by main().
Here is the caller graph for this function:| void N_HIDE_STR | ( | char * | buf, |
| ... | |||
| ) |
reconstruct hidden string from variadic char arguments
reconstruct hidden string from variadic char arguments
| buf | the variable which will receive the string. Must be large enough to hold all arguments. |
Definition at line 458 of file n_common.c.
Referenced by main().
Here is the caller graph for this function:| int n_popen | ( | char * | cmd, |
| size_t | read_buf_size, | ||
| void ** | nstr_output, | ||
| int * | ret | ||
| ) |
shortcut for popen usage
shortcut for popen usage
| 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 allocated |
| 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 179 of file n_common.c.
References __n_assert, free_nstr, LOG_ERR, n_log, new_nstr(), and nstrprintf_cat.
Referenced by addr2line(), main(), and n_get_current_dir_hd_serial().
Here is the call graph for this function:
Here is the caller graph for this function:| void sigchld_handler | ( | int | sig | ) |
reap zombie processes
reap zombie processes
| sig | signal type handle |
Definition at line 252 of file n_common.c.
References LOG_DEBUG, and n_log.
Referenced by sigchld_handler_installer().
Here is the caller graph for this function:| int sigchld_handler_installer | ( | ) |
install signal SIGCHLD handler
install signal SIGCHLD handler
Definition at line 266 of file n_common.c.
References LOG_ERR, n_log, and sigchld_handler().
Referenced by main(), and n_daemonize_ex().
Here is the call graph for this function:
Here is the caller graph for this function:| pid_t system_nb | ( | const char * | command, |
| int * | infp, | ||
| int * | outfp | ||
| ) |
non-blocking system call
non-blocking system call
| command | to call |
| infp | stdin file descriptor holder or NULL |
| outfp | stdout file descriptor holder or NULL |
Definition at line 389 of file n_common.c.
References __n_assert, LOG_ERR, and n_log.
Referenced by main().
Here is the caller graph for this function: