Nilorea Library common api test.
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#ifndef __windows__
#include <sys/wait.h>
#endif
void usage(void) {
fprintf(stderr,
" -v version\n"
" -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
" -h help\n");
}
void process_args(int argc, char** argv) {
int getoptret = 0,
while ((getoptret = getopt(argc, argv, "hvV:")) != EOF) {
switch (getoptret) {
case 'v':
fprintf(stderr, "Date de compilation : %s a %s.\n", __DATE__, __TIME__);
exit(1);
case 'V':
if (!strncmp("LOG_NULL", optarg, 5)) {
} else {
if (!strncmp("LOG_NOTICE", optarg, 6)) {
} else {
if (!strncmp("LOG_INFO", optarg, 7)) {
} else {
if (!strncmp("LOG_ERR", optarg, 5)) {
} else {
if (!strncmp("LOG_DEBUG", optarg, 5)) {
} else {
fprintf(stderr, "%s n'est pas un niveau de log valide.\n", optarg);
exit(-1);
}
}
}
}
}
break;
default:
case '?': {
if (optopt == 'V') {
fprintf(stderr, "\n Missing log level\n");
} else if (optopt == 'p') {
fprintf(stderr, "\n Missing port\n");
} else if (optopt != 's') {
fprintf(stderr, "\n Unknow missing option %c\n", optopt);
}
usage();
exit(1);
}
case 'h': {
usage();
exit(1);
}
}
}
}
}
int main(int argc, char** argv) {
process_args(argc, argv);
inlined_func();
n_log(
LOG_INFO,
"TRUE,true values: %d,%d / FALSE,false value: %d,%d", TRUE,
true, FALSE,
false);
char* data = NULL;
error:
} else {
}
}
char *dir = NULL, *name = NULL;
int ret = -1;
if (n_popen("ls -ltr", 2048, (void*)&out, &ret) == TRUE) {
} else {
}
char hidden_str[47] = "";
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');
printf("hidden str:%s\n", hidden_str);
#ifndef __windows__
wait(&pid);
#endif
n_abort(
"Testing abort before exit");
exit(0);
}
#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.