31#define _GNU_SOURCE_WAS_NOT_DEFINED
35#ifdef _GNU_SOURCE_WAS_NOT_DEFINED
56 n_log(
LOG_ERR,
"Could not allocate the internal hash table because it's already done");
65 n_log(
LOG_ERR,
"Could not allocate the internal hash with size %zu", max);
68 n_log(
LOG_DEBUG,
"LOGGING: nodup system activated with a hash table of %zu cells", max);
99static char*
get_nodup_key(
const char* file,
const char* func,
int line) {
120 nstrprintf(nstr,
"%s%s%s%d", file, func, prefix, line);
207void _n_nodup_log(
int LEVEL,
const char* file,
const char* func,
int line,
const char* format, ...) {
215 char* syslogbuffer = NULL;
217 va_start(args, format);
218 if (
vasprintf(&syslogbuffer, format, args) == -1) {
220 n_log(
LOG_ERR,
"=>%s:%s:%d unable to parse '%s', %s", file, func, line, format, strerror(error));
236 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
255 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
273void _n_nodup_log_indexed(
int LEVEL,
const char* prefix,
const char* file,
const char* func,
int line,
const char* format, ...) {
277 char* syslogbuffer = NULL;
279 va_start(args, format);
280 if (
vasprintf(&syslogbuffer, format, args) == -1) {
282 n_log(
LOG_ERR,
"=>%s:%s:%d unable to parse '%s:%s', %s", file, func, line, prefix, format, strerror(error));
298 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
317 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
338 char* tmpfile = NULL;
342 n_log(
LOG_ERR,
"could not create tmp file name from filename %s",
_str(file));
346 int fd = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600);
348 n_log(
LOG_ERR,
"could not create file %s with 0600 permissions",
_str(tmpfile));
353 out = fdopen(fd,
"wb");
366 if (rename(tmpfile, file) != 0) {
368 n_log(
LOG_ERR,
"could not rename '%s' to '%s' , %s", tmpfile, file,
#define __n_assert(__ptr, __ret)
macro to assert things
#define _str(__PTR)
define true
#define Free(__ptr)
Free Handler to get errors.
union HASH_DATA data
data inside the node
LIST ** hash_table
HASH_CLASSIC mode: preallocated hash table.
size_t size
size of the hash table
int destroy_ht(HASH_TABLE **table)
empty a table and destroy it
HASH_TABLE * new_ht(size_t size)
Create a hash table with the given size.
int empty_ht(HASH_TABLE *table)
empty a table
int ht_put_string(HASH_TABLE *table, const char *key, char *string)
put a string value (copy/dup) with given key in the targeted hash table
HASH_NODE * ht_get_node(HASH_TABLE *table, const char *key)
get node at 'key' from 'table'
structure of a hash table node
structure of a hash table
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper, safe for node removal during iteration.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Logging function.
int init_nodup_log(size_t max)
initialize the no duplicate logging system
int dump_nodup_log(char *file)
Dump the duplicate error log hash table in a file The table is first written to a temporary file whic...
int close_nodup_log()
Empty nodup logtable and close the no duplicate logging session.
void _n_nodup_log(int LEVEL, const char *file, const char *func, int line, const char *format,...)
Logging function.
int empty_nodup_table()
Empty the nodup internal table.
void _n_nodup_log_indexed(int LEVEL, const char *prefix, const char *file, const char *func, int line, const char *format,...)
Logging function.
#define strprintf(__n_var,...)
Macro to quickly allocate and sprintf to a char.
#define nstrprintf(__nstr_var, __format,...)
Macro to quickly allocate and sprintf to N_STR.
A box including a string and his lenght.
Common headers and low-level functions & define.
Hash functions and table.
List structures and definitions.
int vasprintf(char **strp, const char *fmt, va_list ap)
snprintf from a va_list, helper for asprintf
int check_n_log_dup(const char *log, const char *file, const char *func, int line)
check if a log was already done or not at the given line, func, file
int check_n_log_dup_indexed(const char *log, const char *file, const char *func, int line, const char *prefix)
check if a log was already done or not at the given line, func, file
static char * get_nodup_key(const char *file, const char *func, int line)
internal, get a key for a log entry
static HASH_TABLE * _n_nodup_table
internal: no dup hash_table log save
static char * get_nodup_indexed_key(const char *file, const char *func, const char *prefix, int line)
internal, get a key for an indexed log entry
Generic No Dup Log system.
N_STR and string function declaration.