Table of Contents
- COMMONS: macros, headers, defines, timers, allocators,...
- Functions
- Defines
- Functions Documentation
- function system_nb
- function sigchld_handler_installer
- function sigchld_handler
- function n_spawn_wait_cancel
- function n_spawn_wait
- function n_spawn_pipe_write
- function n_spawn_pipe_read
- function n_spawn_pipe_open_read
- function n_spawn_pipe_open
- function n_spawn_pipe_close
- function n_spawn_detached
- function n_popen
- function n_open_with_default
- function n_get_file_extension
- function n_daemonize_ex
- function n_daemonize
- function n_abort
- function log_environment
- function get_prog_name
- function get_prog_dir
- function get_computer_name
- function file_exist
- function N_HIDE_STR
- Macros Documentation
- define write_lock
- define unlock
- define rw_lock_destroy
- define read_lock
- define randomize
- define next_odd
- define next_even
- define init_lock
- define init_error_check
- define ifzero
- define iftrue
- define ifnull
- define iffalse
- define get_error
- define equal_if
- define endif
- define checkerror
- define _strw
- define _strp
- define _str
- define _nstrp
- define _nstr
- define __n_assert
- define STOPWANTED
- define STOPPED
- define SET
- define Reallocz
- define Realloc
- define RWLOCK_LOGLEVEL
- define RUNNING
- define PAUSED
- define N_DAEMON_NO_UMASK
- define N_DAEMON_NO_STD_REDIRECT
- define N_DAEMON_NO_SIGCHLD_IGN
- define N_DAEMON_NO_SIGCHLD_HANDLER
- define N_DAEMON_NO_SETSID
- define N_DAEMON_NO_DOUBLE_FORK
- define N_DAEMON_NO_CLOSE
- define N_DAEMON_NO_CHDIR
- define Malloc
- define GET
- define FreeNoLog
- define Free
- define FORCE_INLINE
- define FALL_THROUGH
- define DEFAULT
- define CONCAT_BUILDER
- define CONCAT
- define CALL_RETRY
- define BYTEORDER_LITTLE_ENDIAN
- define BYTEORDER_BIG_ENDIAN
- define Alloca
COMMONS: macros, headers, defines, timers, allocators,...
Functions
| Name | |
|---|---|
| pid_t | system_nb(const char * command, int * infp, int * outfp) non-blocking system call |
| int | sigchld_handler_installer(void ) install signal SIGCHLD handler |
| void | sigchld_handler(int sig) reap zombie processes |
| int | n_spawn_wait_cancel(const char * program, const char *const * args, int * exit_code, const volatile int * cancel) Run a program and wait for it, ending it early when asked. |
| int | n_spawn_wait(const char * program, const char *const * args, int * exit_code) Run a program with arguments and wait for it to finish. |
| int | n_spawn_pipe_write(N_SPAWN_PIPE * pipe, const void * data, size_t len) Write to a program's standard input, all of it. |
| size_t | n_spawn_pipe_read(N_SPAWN_PIPE * pipe, void * data, size_t len) Read from a program's standard output, as much as asked for. |
| N_SPAWN_PIPE * | n_spawn_pipe_open_read(const char * program, const char *const * args, const char * log_path) Start a program whose standard output the caller reads. |
| N_SPAWN_PIPE * | n_spawn_pipe_open(const char * program, const char *const * args, const char * log_path) Start a program whose standard input is fed by the caller. |
| int | n_spawn_pipe_close(N_SPAWN_PIPE ** pipe, int stop, int * exit_code) End a program's input, or end the program, and wait for it. |
| int | n_spawn_detached(const char * program, const char *const * args) Start a program and do not wait for it. |
| int | n_popen(char * cmd, size_t read_buf_size, void ** nstr_output, int * ret) shortcut for popen usage |
| int | n_open_with_default(const char * path) Open a file or a URL with whatever the desktop opens it with. |
| char * | n_get_file_extension(char path[]) get the file extension from a path |
| int | n_daemonize_ex(int mode) daemonize the current process with the given mode flags |
| int | n_daemonize(void ) daemonize the current process |
| void | n_abort(char const * format, ... ) htonl for 64 bits numbers |
| void | log_environment(int loglevel) log environment variables at the given log level |
| char * | get_prog_name(void ) get running program name |
| char * | get_prog_dir(void ) get running program directory |
| int | get_computer_name(char * computer_name, size_t len) get the computer name into the given buffer |
| int | file_exist(const char * filename) test file presence |
| void | N_HIDE_STR(char * buf, ... ) reconstruct hidden string from variadic char arguments |
Defines
| Name | |
|---|---|
| write_lock(__rwlock_mutex) Macro for acquiring a write lock on a rwlock mutex. |
|
| unlock(__rwlock_mutex) Macro for releasing read/write lock a rwlock mutex. |
|
| rw_lock_destroy(__rwlock_mutex) Macro to destroy rwlock mutex. |
|
| read_lock(__rwlock_mutex) Macro for acquiring a read lock on a rwlock mutex. |
|
| randomize() Initialize the random sequence with time. |
|
| next_odd(__val) next odd helper |
|
| next_even(__val) next even helper |
|
| init_lock(__rwlock_mutex) Macro for initializing a rwlock. |
|
| init_error_check() init error checking in a function |
|
| ifzero error checker type if( 0 != toto ) |
|
| iftrue error checker type if( toto == FALSE ) |
|
| ifnull error checker type if( !toto ) |
|
| iffalse error checker type if( toto == FALSE ) |
|
| get_error() pop up errors if any |
|
| equal_if(__a, __cond, __b) if( a , condition, b ) then a = b |
|
| endif close a ifwhatever block |
|
| checkerror() check for errors |
|
| _strw(__PTR) String or " " string for config purposes. |
|
| _strp(__PTR) String or NULL pointer for testing purposes. |
|
| _str(__PTR) define true |
|
| _nstrp(__PTR) N_STR or NULL pointer for testing purposes. |
|
| _nstr(__PTR) N_STR or "NULL" string for logging purposes. |
|
| __n_assert(__ptr, __ret) macro to assert things |
|
| STOPWANTED Value of the state of an application who want to stop his activity. |
|
| STOPPED Value of the state of an application who is stopped. |
|
| SET Flag for SET something , passing as a function parameter. |
|
| Reallocz(__ptr, __struct, __old_size, __size) Realloc + zero new memory zone Handler to get errors. |
|
| Realloc(__ptr, __struct, __size) Realloc Handler to get errors. |
|
| RWLOCK_LOGLEVEL flag to tell the API to disable DEBUG log on locks |
|
| RUNNING Value of the state of an application who is running. |
|
| PAUSED Value of the state of an application who is paused. |
|
| N_DAEMON_NO_UMASK daemonize flag: do not call umask( 0 ) |
|
| N_DAEMON_NO_STD_REDIRECT daemonize flag: just do not redirect stdin/out/err to /dev/null |
|
| N_DAEMON_NO_SIGCHLD_IGN daemonize flag: do not ignore SIGCHLD |
|
| N_DAEMON_NO_SIGCHLD_HANDLER daemonize flag: do not use internal zombie SIGCHLD handler |
|
| N_DAEMON_NO_SETSID daemonize flag: do not call setsid |
|
| N_DAEMON_NO_DOUBLE_FORK daemonize flag: do not double fork |
|
| N_DAEMON_NO_CLOSE daemonize flag: no descriptor close at all |
|
| N_DAEMON_NO_CHDIR daemonize flag: do not call chdir("/") |
|
| Malloc(__ptr, __struct, __size) Malloc Handler to get errors and set to 0. |
|
| GET Flag for GET something , passing as a function parameter. |
|
| FreeNoLog(__ptr) Free Handler without log. |
|
| Free(__ptr) Free Handler to get errors. |
|
| FORCE_INLINE FORCE_INLINE portable macro. |
|
| FALL_THROUGH set windows if true |
|
| DEFAULT Default APP_STATUS Value. |
|
| CONCAT_BUILDER(a, b) CONCAT macro helper. |
|
| CONCAT(a, b) Concatenate two macro. |
|
| CALL_RETRY(__retvar, __expression, __max_tries) TEMP_FAILURE gnu macro portable version. |
|
| BYTEORDER_LITTLE_ENDIAN Little endian macro value. |
|
| BYTEORDER_BIG_ENDIAN Big endian macro value. |
|
| Alloca(__ptr, __size) Malloca Handler to get errors and set to 0. |
Functions Documentation
function system_nb
pid_t system_nb(
const char * command,
int * infp,
int * outfp
)
non-blocking system call
Parameters:
- command to call
- infp stdin file descriptor holder or NULL
- outfp stdout file descriptor holder or NULL
Return: The system command pid or -1
Non blocking system call.
non-blocking system call
function sigchld_handler_installer
int sigchld_handler_installer(
void
)
install signal SIGCHLD handler
Return: TRUE or FALSE
install signal SIGCHLD handler to reap zombie processes
install signal SIGCHLD handler
function sigchld_handler
void sigchld_handler(
int sig
)
reap zombie processes
Parameters:
- sig signal type handle
Handles SIGCHLD issues when forking.
reap zombie processes
function n_spawn_wait_cancel
int n_spawn_wait_cancel(
const char * program,
const char *const * args,
int * exit_code,
const volatile int * cancel
)
Run a program and wait for it, ending it early when asked.
Parameters:
- program Program to run: a name on the PATH or a path.
- args Its arguments after the program itself, NULL terminated. May be NULL for none.
- exit_code As n_spawn_wait(); -1 when the program was stopped. May be NULL.
- cancel Flag another thread raises to stop the program. Read, never written. NULL waits as n_spawn_wait() does.
Return: TRUE when the program ran and exited with 0, FALSE when it failed or was stopped.
n_spawn_wait() for a program that can run for minutes, a download say, whose caller must be able to stop it. While the program runs the flag is looked at every tenth of a second; once it is non-zero the program is ended - SIGTERM, then SIGKILL two seconds later on POSIX, TerminateProcess on Windows - and reaped, and the call returns FALSE. What the program had written by then is the caller's to remove.
function n_spawn_wait
int n_spawn_wait(
const char * program,
const char *const * args,
int * exit_code
)
Run a program with arguments and wait for it to finish.
Parameters:
- program Program to run: a name on the PATH or a path.
- args Its arguments after the program itself, NULL terminated. May be NULL for none.
- exit_code Receives the program's exit code when it ran to the end, 127 when it could not be found or started on POSIX, -1 when it was ended by a signal. May be NULL.
Return: TRUE when the program ran and exited with 0, FALSE otherwise; the reason is in exit_code and the log.
The waiting counterpart of n_spawn_detached(), for a tool whose result the caller needs before going on: a converter, a compressor. No shell is involved, so every argument arrives whole whatever it contains. On POSIX the program is found on the PATH, started with fork and execvp and reaped with waitpid; on Windows it is CreateProcess with each argument quoted and a wait on its handle. The caller's thread blocks for as long as the program runs: call it from a worker, not from an interface thread.
function n_spawn_pipe_write
int n_spawn_pipe_write(
N_SPAWN_PIPE * pipe,
const void * data,
size_t len
)
Write to a program's standard input, all of it.
Parameters:
- pipe The running program. NULL fails.
- data What to write. May be NULL when
lenis 0. - len How many bytes.
Return: TRUE when every byte was written, FALSE when the program is gone or the write failed.
Blocks while the program is not reading, which is how a fast producer is held to a slow consumer's pace. A program that has ended, or closed its input, makes this return FALSE rather than raise SIGPIPE: the signal is held back for the calling thread during the write and discarded.
function n_spawn_pipe_read
size_t n_spawn_pipe_read(
N_SPAWN_PIPE * pipe,
void * data,
size_t len
)
Read from a program's standard output, as much as asked for.
Parameters:
- pipe The running program. NULL fails.
- data Where the bytes go. May be NULL when
lenis 0. - len How many are wanted.
Return: How many were read, fewer than len only at the end of the output; SIZE_MAX on a read error or a pipe started for writing.
Blocks until len bytes have come or the program's output has ended, so a short count is the end of the output, as with fread(). Only for a program started by n_spawn_pipe_open_read().
function n_spawn_pipe_open_read
N_SPAWN_PIPE * n_spawn_pipe_open_read(
const char * program,
const char *const * args,
const char * log_path
)
Start a program whose standard output the caller reads.
Parameters:
- program Program to run: a name on the PATH or a path.
- args Its arguments after the program itself, NULL terminated. May be NULL for none.
- log_path File that receives the program's standard error, created or truncated. NULL leaves it as it is.
Return: The running program, owned by the caller and released by n_spawn_pipe_close(), or NULL when it could not be started. On POSIX a program that is not found shows as an empty output and exit code 127 at the close.
The other direction of n_spawn_pipe_open(): for a tool that produces a stream, a decoder writing raw frames, a lister writing records. No shell is involved. The caller reads what the program writes with n_spawn_pipe_read(), which sees the end of it when the program exits or closes its output. The program's standard error goes to log_path when given - what it says must not be mixed into what it produces - and is left as the caller's otherwise. Its standard input is the null device, so a program that would ask a terminal something reads an end of input instead of waiting for ever.
The read end is never inherited by another program the caller starts.
function n_spawn_pipe_open
N_SPAWN_PIPE * n_spawn_pipe_open(
const char * program,
const char *const * args,
const char * log_path
)
Start a program whose standard input is fed by the caller.
Parameters:
- program Program to run: a name on the PATH or a path.
- args Its arguments after the program itself, NULL terminated. May be NULL for none.
- log_path File that receives the program's standard output and error, created or truncated. NULL leaves them as they are.
Return: The running program, owned by the caller and released by n_spawn_pipe_close(), or NULL when it could not be started. On POSIX a program that is not found is only learnt of at the first write or at the close, as exit code 127.
For a tool that takes a stream rather than a file: an encoder fed raw frames, a compressor fed a buffer. No shell is involved, as with n_spawn_wait(). The program reads what n_spawn_pipe_write() sends and sees the end of its input at n_spawn_pipe_close(). Its standard output and error go to log_path when given, so what it said can be read after it failed, and are left as the caller's otherwise.
The write end is never inherited by another program the caller starts, which would otherwise hold the pipe open and keep this one waiting for an end of input that never comes.
function n_spawn_pipe_close
int n_spawn_pipe_close(
N_SPAWN_PIPE ** pipe,
int stop,
int * exit_code
)
End a program's input, or end the program, and wait for it.
Parameters:
- pipe Address of the running program. NULL or *NULL is a no-op that returns FALSE.
- stop Non-zero to end the program rather than let it finish.
- exit_code Receives its exit code, 127 when it could not be found or started on POSIX, -1 when it was ended by a signal or stopped. May be NULL.
Return: TRUE when it finished by itself with exit code 0, FALSE otherwise.
With stop at zero the caller's end is closed and the program waited for as long as it takes: for a program being written to that is the end of its input, which it finishes with; for one being read from it is a broken pipe at its next write, which ends it. With stop set it is ended first - SIGTERM then SIGKILL two seconds later on POSIX, TerminateProcess on Windows - for a caller abandoning the work. Either way it is reaped, and *pipe is freed and set to NULL.
function n_spawn_detached
int n_spawn_detached(
const char * program,
const char *const * args
)
Start a program and do not wait for it.
Parameters:
- program Program to run: a name on the PATH or a path.
- args Its arguments after the program itself, NULL terminated. May be NULL for none.
Return: TRUE when the program was started, FALSE when it could not be (on POSIX a program that is not found is reported by the child and still counts as started; the caller learns of it from the log).
For handing a file to another application - an image editor, a viewer - that must outlive the caller's interest in it. No shell is involved: the arguments are passed as they are, so a file name with spaces, quotes or a semicolon in it is one argument and nothing else. On POSIX the program is found on the PATH and started through a double fork in a session of its own, so it leaves no zombie and a terminal closing does not take it with it; on Windows it is CreateProcess with each argument quoted.
function n_popen
int n_popen(
char * cmd,
size_t read_buf_size,
void ** nstr_output,
int * ret
)
shortcut for popen usage
Parameters:
- 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.
Return: TRUE or FALSE
launch a command and return output and status
shortcut for popen usage
function n_open_with_default
int n_open_with_default(
const char * path
)
Open a file or a URL with whatever the desktop opens it with.
Parameters:
- path File path or URL.
Return: TRUE when the opener was started, FALSE otherwise.
xdg-open on Linux and the BSDs, open on macOS, ShellExecute on Windows. Detached, as n_spawn_detached().
function n_get_file_extension
char * n_get_file_extension(
char path[]
)
get the file extension from a path
Parameters:
- path the path + filename
Return: a pointer to the first extension character or NULL
get extension of path+filename
get the file extension from a path
function n_daemonize_ex
int n_daemonize_ex(
int mode
)
daemonize the current process with the given mode flags
Parameters:
- 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
Return: TRUE or FALSE
Daemonize program.
daemonize the current process with the given mode flags
function n_daemonize
int n_daemonize(
void
)
daemonize the current process
Return: TRUE or FALSE
Daemonize program.
daemonize the current process
function n_abort
void n_abort(
char const * format,
...
)
htonl for 64 bits numbers
Parameters:
- format printf style format and args
abort program with a text
ntonl for 64 bits numbers
exit and print log to stderr
htonl for 64 bits numbers
function log_environment
void log_environment(
int loglevel
)
log environment variables at the given log level
Parameters:
- loglevel the loglevel used to log the environment
log environment variables in syslog
log environment variables at the given log level
function get_prog_name
char * get_prog_name(
void
)
get running program name
Return: A copy of the current program name inside a string
get current program name
get running program name
function get_prog_dir
char * get_prog_dir(
void
)
get running program directory
Return: A copy of the current program running directory inside a string
get current program running directory
get running program directory
function get_computer_name
int get_computer_name(
char * computer_name,
size_t len
)
get the computer name into the given buffer
Parameters:
- computer_name allocated buffer to hold the computer name
- len size of computer_name variable
Return: TRUE or FALSE
get the computer name
get the computer name into the given buffer
function file_exist
int file_exist(
const char * filename
)
test file presence
Parameters:
- filename Path/name of the file
Return: TRUE or FALSE
test if file exist and if it's readable
test file presence
function N_HIDE_STR
void N_HIDE_STR(
char * buf,
...
)
reconstruct hidden string from variadic char arguments
Parameters:
- buf the variable which will receive the string. Must be large enough to hold all arguments.
Warning: No bounds checking is performed. The caller must ensure buf is large enough.
store a hidden version of a string
reconstruct hidden string from variadic char arguments
Macros Documentation
define write_lock
#define write_lock(
__rwlock_mutex
)
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "write lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_wrlock(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while write locking %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})
Macro for acquiring a write lock on a rwlock mutex.
define unlock
#define unlock(
__rwlock_mutex
)
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "unlock lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_unlock(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while unlocking %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})
Macro for releasing read/write lock a rwlock mutex.
define rw_lock_destroy
#define rw_lock_destroy(
__rwlock_mutex
)
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "destroy lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_destroy(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while destroying %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})
Macro to destroy rwlock mutex.
define read_lock
#define read_lock(
__rwlock_mutex
)
({ \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "read lock %s", #__rwlock_mutex); \
__ret = pthread_rwlock_rdlock(&(__rwlock_mutex)); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while read locking %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
} while (0); \
__ret; \
})
Macro for acquiring a read lock on a rwlock mutex.
define randomize
#define randomize(
)
{ \
srand((unsigned)time(NULL)); \
rand(); \
}
Initialize the random sequence with time.
define next_odd
#define next_odd(
__val
)
(((__val) % 2 == 0) ? ((__val) + 1) : (__val))
next odd helper
define next_even
#define next_even(
__val
)
(((__val) % 2 == 0) ? (__val) : ((__val) + 1))
next even helper
define init_lock
#define init_lock(
__rwlock_mutex
)
({ \
pthread_rwlockattr_t __attr; \
pthread_rwlockattr_init(&__attr); \
int __ret = 0; \
do { \
n_log(RWLOCK_LOGLEVEL, "init_lock %s", #__rwlock_mutex); \
__rwlock_mutex = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER; \
__ret = pthread_rwlock_init(&(__rwlock_mutex), &__attr); \
if (__ret != 0) { \
n_log(LOG_ERR, "Error %s while initializing %s at %s:%s:%d", strerror(__ret), #__rwlock_mutex, __FILE__, __func__, __LINE__); \
} \
pthread_rwlockattr_destroy(&__attr); \
} while (0); \
__ret; \
})
Macro for initializing a rwlock.
define init_error_check
#define init_error_check(
)
static int ___error__check_flag = FALSE;
init error checking in a function
define ifzero
#define ifzero if( 0 ==
error checker type if( 0 != toto )
define iftrue
#define iftrue if( TRUE ==
error checker type if( toto == FALSE )
define ifnull
#define ifnull if( !
error checker type if( !toto )
define iffalse
#define iffalse if( FALSE ==
error checker type if( toto == FALSE )
define get_error
#define get_error(
)
(___error__check_flag == TRUE)
pop up errors if any
define equal_if
#define equal_if(
__a,
__cond,
__b
)
if ((__a)__cond(__b)) { \
__a = __b; \
}
if( a , condition, b ) then a = b
define endif
#define endif ){ \
___error__check_flag = TRUE; \
n_log(LOG_ERR, "First err was at line %d of %s", __LINE__, __FILE__); \
}
close a ifwhatever block
define checkerror
#define checkerror(
)
if (___error__check_flag == TRUE) { \
n_log(LOG_ERR, "checkerror return false at line %d of %s", __LINE__, __FILE__); \
goto error; \
}
check for errors
define _strw
#define _strw(
__PTR
)
((__PTR) ? (__PTR) : " ")
String or " " string for config purposes.
define _strp
#define _strp(
__PTR
)
((__PTR) ? (__PTR) : NULL)
String or NULL pointer for testing purposes.
define _str
#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
define _nstrp
#define _nstrp(
__PTR
)
((__PTR && __PTR->data) ? (__PTR->data) : NULL)
N_STR or NULL pointer for testing purposes.
define _nstr
#define _nstr(
__PTR
)
((__PTR && __PTR->data) ? (__PTR->data) : "NULL")
N_STR or "NULL" string for logging purposes.
define __n_assert
#define __n_assert(
__ptr,
__ret
)
if (!(__ptr)) { \
n_log(LOG_DEBUG, "if( !(%s) ) assert at line %d of %s", #__ptr, __LINE__, __FILE__); \
__ret; \
}
macro to assert things
define STOPWANTED
#define STOPWANTED 1002
Value of the state of an application who want to stop his activity.
define STOPPED
#define STOPPED 1003
Value of the state of an application who is stopped.
define SET
#define SET 1234
Flag for SET something , passing as a function parameter.
define Reallocz
#define Reallocz(
__ptr,
__struct,
__old_size,
__size
)
({ \
int __n_errno = 0; \
errno = 0; \
void* __new_ptr = ((__size) && (sizeof(__struct)) && ((__size) > SIZE_MAX / sizeof(__struct))) ? NULL : (__struct*)realloc(__ptr, __size); \
__n_errno = errno; \
if (!__new_ptr) { \
n_log(LOG_ERR, "( %s *)realloc( %s * sizeof( %zu ) ) %s at line %d of %s", #__ptr, #__struct, (size_t)(__size), (__n_errno == 0) ? "realloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
__ptr = __new_ptr; \
if (__size > __old_size) memset(((char*)__ptr + __old_size), 0, __size - __old_size); \
} \
(__new_ptr != NULL) ? TRUE : FALSE; \
})
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).
define Realloc
#define Realloc(
__ptr,
__struct,
__size
)
({ \
int __n_errno = 0; \
errno = 0; \
void* __new_ptr = ((__size) && (sizeof(__struct)) && ((__size) > SIZE_MAX / sizeof(__struct))) ? NULL : (__struct*)realloc(__ptr, (__size) * sizeof(__struct)); \
__n_errno = errno; \
if (!__new_ptr) { \
n_log(LOG_ERR, "( %s *)realloc( %s * sizeof( %zu ) ) %s at line %d of %s", #__ptr, #__struct, (size_t)(__size), (__n_errno == 0) ? "realloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
__ptr = __new_ptr; \
} \
(__new_ptr != NULL) ? TRUE : FALSE; \
})
Realloc Handler to get errors.
Returns TRUE on success, FALSE on failure. On failure the original pointer is preserved (not set to NULL).
define RWLOCK_LOGLEVEL
#define RWLOCK_LOGLEVEL LOG_NULL
flag to tell the API to disable DEBUG log on locks
define RUNNING
#define RUNNING 1001
Value of the state of an application who is running.
define PAUSED
#define PAUSED 1004
Value of the state of an application who is paused.
define N_DAEMON_NO_UMASK
#define N_DAEMON_NO_UMASK 32
daemonize flag: do not call umask( 0 )
define N_DAEMON_NO_STD_REDIRECT
#define N_DAEMON_NO_STD_REDIRECT 4
daemonize flag: just do not redirect stdin/out/err to /dev/null
define N_DAEMON_NO_SIGCHLD_IGN
#define N_DAEMON_NO_SIGCHLD_IGN 128
daemonize flag: do not ignore SIGCHLD
define N_DAEMON_NO_SIGCHLD_HANDLER
#define N_DAEMON_NO_SIGCHLD_HANDLER 256
daemonize flag: do not use internal zombie SIGCHLD handler
define N_DAEMON_NO_SETSID
#define N_DAEMON_NO_SETSID 16
daemonize flag: do not call setsid
define N_DAEMON_NO_DOUBLE_FORK
#define N_DAEMON_NO_DOUBLE_FORK 8
daemonize flag: do not double fork
define N_DAEMON_NO_CLOSE
#define N_DAEMON_NO_CLOSE 2
daemonize flag: no descriptor close at all
define N_DAEMON_NO_CHDIR
#define N_DAEMON_NO_CHDIR 64
daemonize flag: do not call chdir("/")
define Malloc
#define Malloc(
__ptr,
__struct,
__size
)
{ \
int __n_errno = 0; \
errno = 0; \
__ptr = (__struct*)calloc(__size, sizeof(__struct)); \
__n_errno = errno; \
if (!__ptr) { \
n_log(LOG_ERR, "( %s *)calloc( %zu , sizeof( %s ) ) %s at line %d of %s", #__ptr, (size_t)(__size), #__struct, (__n_errno == 0) ? "malloc error" : strerror(__n_errno), __LINE__, __FILE__); \
} \
}
Malloc Handler to get errors and set to 0.
define GET
#define GET 4321
Flag for GET something , passing as a function parameter.
define FreeNoLog
#define FreeNoLog(
__ptr
)
if (__ptr) { \
free(__ptr); \
__ptr = NULL; \
}
Free Handler without log.
define Free
#define Free(
__ptr
)
if (__ptr) { \
free(__ptr); \
__ptr = NULL; \
} else { \
n_log(LOG_DEBUG, "Free( %s ) already done or NULL at line %d of %s", #__ptr, __LINE__, __FILE__); \
}
Free Handler to get errors.
define FORCE_INLINE
#define FORCE_INLINE static inline __attribute__((always_inline))
FORCE_INLINE portable macro.
define FALL_THROUGH
#define FALL_THROUGH /* fall through */ \
((void)0)
set windows if true
fall through macro for switch cases, avoid warning at compilation
define DEFAULT
#define DEFAULT 1000
Default APP_STATUS Value.
define CONCAT_BUILDER
#define CONCAT_BUILDER(
a,
b
)
a##b
CONCAT macro helper.
define CONCAT
#define CONCAT(
a,
b
)
CONCAT_BUILDER(a, b)
Concatenate two macro.
define CALL_RETRY
#define CALL_RETRY(
__retvar,
__expression,
__max_tries
)
do { \
int __nb_retries = 0; \
do { \
__retvar = (__expression); \
__nb_retries++; \
} while (__retvar == -1 && errno == EINTR && __nb_retries < (__max_tries)); \
} while (0)
TEMP_FAILURE gnu macro portable version.
define BYTEORDER_LITTLE_ENDIAN
#define BYTEORDER_LITTLE_ENDIAN 0
Little endian macro value.
define BYTEORDER_BIG_ENDIAN
#define BYTEORDER_BIG_ENDIAN 1
Big endian macro value.
define Alloca
#define Alloca(
__ptr,
__size
)
{ \
int __n_errno = 0; \
errno = 0; \
__ptr = alloca(__size); \
__n_errno = errno; \
if (!__ptr) { \
n_log(LOG_ERR, "%s=alloca( %zu ) %s at line %d of %s", #__ptr, (size_t)(__size), (__n_errno == 0) ? "alloca error" : strerror(__n_errno), __LINE__, __FILE__); \
} else { \
memset(__ptr, 0, __size); \
} \
}
Malloca Handler to get errors and set to 0.
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB