22 fprintf( stderr,
" -v version\n"
23 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
27void process_args(
int argc,
char **argv )
37 while( ( getoptret = getopt( argc, argv,
"hvV:" ) ) != EOF)
42 fprintf( stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__ );
45 if( !strncmp(
"LOG_NULL", optarg, 5 ) )
51 if( !strncmp(
"LOG_NOTICE", optarg, 6 ) )
57 if( !strncmp(
"LOG_INFO", optarg, 7 ) )
63 if( !strncmp(
"LOG_ERR", optarg, 5 ) )
69 if( !strncmp(
"LOG_DEBUG", optarg, 5 ) )
75 fprintf( stderr,
"%s n'est pas un niveau de log valide.\n", optarg );
88 fprintf( stderr,
"\n Missing log level\n" );
90 else if( optopt ==
'p' )
92 fprintf( stderr,
"\n Missing port\n" );
94 else if( optopt !=
's' )
96 fprintf( stderr,
"\n Unknow missing option %c\n", optopt );
119int main(
int argc,
char **argv)
123 process_args( argc, argv );
127 n_log(
LOG_INFO,
"TRUE,true values: %d,%d / FALSE,false value: %d,%d", TRUE,
true, FALSE,
false );
141 Malloc( data,
char, 1024 );
144 Malloc( data,
char, 1024 );
147 Malloc( data,
char, 1024 );
179 char *dir = NULL, *name = NULL ;
188 if(
n_popen(
"ls -ltr", 2048, (
void *)&out, &ret ) == TRUE )
198 char hidden_str[47]=
"";
199 N_HIDE_STR(hidden_str,
'T',
'h',
'i',
's',
' ',
's',
't',
'r',
'i',
'n',
'g',
' ',
'w',
'i',
'l',
'l',
' ',
'b',
'e',
' ',
'h',
'i',
'd',
'd',
'e',
'n',
' ',
'i',
'n',
' ',
't',
'h',
'e',
' ',
'f',
'i',
'n',
'a',
'l',
' ',
'b',
'i',
'n',
'a',
'r',
'y',
'\0');
200 printf(
"hidden str:%s\n" , hidden_str);
204 int pid=
system_nb(
"sleep 3", NULL, NULL );
211 n_abort(
"Testing abort before exit" );
#define FreeNoLog(__ptr)
Free Handler without log.
char * get_prog_name(void)
get current program name
#define get_error()
pop up errors if any
void N_HIDE_STR(char *buf,...)
store a hidden version of a string
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define _str(__PTR)
define true
#define ifzero
error checker type if( 0 != toto )
pid_t system_nb(const char *command, int *infp, int *outfp)
Non blocking system call.
#define iffalse
error checker type if( toto == FALSE )
#define Reallocz(__ptr, __struct, __old_size, __size)
Realloc + zero new memory zone Handler to get errors.
#define next_odd(__val)
next odd helper
#define Alloca(__ptr, __size)
Malloca Handler to get errors and set to 0.
int n_popen(char *cmd, int read_buf_size, void **nstr_output, int *ret)
launch a command abd return output and status
#define endif
close a ifwhatever block
#define ifnull
error checker type if( !toto )
#define _nstrp(__PTR)
N_STR or NULL pointer for testing purposes.
#define next_even(__val)
next odd helper
char * get_prog_dir(void)
get current program running directory
#define FORCE_INLINE
FORCE_INLINE portable macro.
#define iftrue
error checker type if( toto == FALSE )
#define checkerror()
check for errors
void n_abort(char const *format,...)
abort program with a text
int n_daemonize(void)
Daemonize program.
#define init_error_check()
init error checking in a function
#define Realloc(__ptr, __struct, __size)
Realloc Handler to get errors.
int file_exist(const char *filename)
test if file exist and if it's readable
#define Free(__ptr)
Free Handler to get errors.
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
A box including a string and his lenght.
Common headers and low-level hugly functions & define.
N_STR and string function declaration.