43 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
56 while ((
getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
59 fprintf(stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__);
62 if (!strcmp(
"LOG_NULL", optarg))
64 else if (!strcmp(
"LOG_NOTICE", optarg))
66 else if (!strcmp(
"LOG_INFO", optarg))
68 else if (!strcmp(
"LOG_ERR", optarg))
70 else if (!strcmp(
"LOG_DEBUG", optarg))
73 fprintf(stderr,
"%s n'est pas un niveau de log valide.\n", optarg);
80 fprintf(stderr,
"\n Missing log level\n");
81 }
else if (optopt ==
'p') {
82 fprintf(stderr,
"\n Missing port\n");
83 }
else if (optopt !=
's') {
84 fprintf(stderr,
"\n Unknow missing option %c\n", optopt);
102int main(
int argc,
char** argv) {
108 n_log(
LOG_INFO,
"TRUE,true values: %d,%d / FALSE,false value: %d,%d", TRUE,
true, FALSE,
false);
155 char *dir = NULL, *name = NULL;
164 if (
n_popen(
"ls -ltr", 2048, (
void*)&out, &ret) == TRUE) {
171 char hidden_str[47] =
"";
172 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');
173 printf(
"hidden str:%s\n", hidden_str);
181 if (fi && fi->
name) {
192 int pid =
system_nb(
"sleep 3", NULL, NULL);
199 n_abort(
"Testing abort before exit");
void process_args(int argc, char **argv)
#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 even 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.
int n_popen(char *cmd, size_t read_buf_size, void **nstr_output, int *ret)
launch a command and return output and status
size_t nb_items
number of item currently in the list
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper, safe for node removal during iteration.
int list_destroy(LIST **list)
Empty and Free a list container.
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
Structure of a generic LIST container.
#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
time_t filetime
file creation time
int n_scan_dir(const char *dir, LIST *result, const int recurse)
Scan a directory and append only regular files into a sorted list (oldest first).
#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.
Files configuration header.
N_STR and string function declaration.