Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_common.h File Reference

Common headers and low-level hugly functions & define. More...

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <stdint.h>
#include <nilorea/n_log.h>
#include <nilorea/n_enum.h>
#include <alloca.h>
#include <signal.h>
+ Include dependency graph for n_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __EXTENSIONS__
 set windows if true
 
#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)
 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   ){ ___error__check_flag = TRUE ; n_log( LOG_ERR , "First err was at line %d of %s" , __LINE__ , __FILE__ );}
 close a ifwhatever block
 
#define equal_if(__a, __cond, __b)   if( (__a) __cond (__b) ){ __a = __b ; }
 if( a , condition, b ) then a = b
 
#define FALL_THROUGH
 fall through macro for switch cases, avoid warning at compilation
 
#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 htonll(x)   (x)
 htonl for 64 bits numbers
 
#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 + 1) : ( __val )
 next odd helper
 
#define next_odd(__val)   ( (__val)%2 == 0 ) ? (__val) : ( __val + 1 )
 next odd helper
 
#define ntohll(x)   (x)
 ntonl for 64 bits numbers
 
#define PAUSED   1004
 Value of the state of an application who is paused.
 
#define randomize()   { srand((unsigned)time(NULL)); rand(); }
 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 if file exist and if it's readable
 
int get_computer_name (char *computer_name, size_t len)
 abort program with a text
 
char * get_prog_dir (void)
 get current program running directory
 
char * get_prog_name (void)
 get current program name
 
void log_environment (int loglevel)
 log environment in syslog
 
void n_abort (char const *format,...)
 abort program with a text
 
int n_daemonize (void)
 Daemonize program.
 
int n_daemonize_ex (int mode)
 Daemonize program.
 
char * n_get_file_extension (char path[])
 get extension of path+filename
 
void N_HIDE_STR (char *buf,...)
 store a hidden version of a string
 
int n_popen (char *cmd, int read_buf_size, void **nstr_output, int *ret)
 launch a command abd return output and status
 
void sigchld_handler (int sig)
 Handles SIGCHLD issues when forking.
 
int sigchld_handler_installer ()
 install signal SIGCHLD handler to reap zombie processes
 
pid_t system_nb (const char *command, int *infp, int *outfp)
 Non blocking system call.
 

Detailed Description

Common headers and low-level hugly functions & define.

Author
Castagnier Mickael
Version
1.0
Date
24/03/05

Definition in file n_common.h.