23 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
27void process_args(
int argc,
char** argv) {
36 while ((getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
39 fprintf(stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__);
42 if (!strncmp(
"LOG_NULL", optarg, 5)) {
45 if (!strncmp(
"LOG_NOTICE", optarg, 6)) {
48 if (!strncmp(
"LOG_INFO", optarg, 7)) {
51 if (!strncmp(
"LOG_ERR", optarg, 5)) {
54 if (!strncmp(
"LOG_DEBUG", optarg, 5)) {
57 fprintf(stderr,
"%s n'est pas un niveau de log valide.\n", optarg);
68 fprintf(stderr,
"\n Missing log level\n");
69 }
else if (optopt ==
'p') {
70 fprintf(stderr,
"\n Missing port\n");
71 }
else if (optopt !=
's') {
72 fprintf(stderr,
"\n Unknow missing option %c\n", optopt);
90int main(
int argc,
char** argv) {
92 process_args(argc, argv);
96 n_log(
LOG_INFO,
"TRUE,true values: %d,%d / FALSE,false value: %d,%d", TRUE,
true, FALSE,
false);
143 char *dir = NULL, *name = NULL;
152 if (n_popen(
"ls -ltr", 2048, (
void*)&out, &ret) == TRUE) {
159 char hidden_str[47] =
"";
160 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');
161 printf(
"hidden str:%s\n", hidden_str);
165 int pid =
system_nb(
"sleep 3", NULL, NULL);
172 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.
#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 functions & define.
N_STR and string function declaration.