13#define _GNU_SOURCE_WAS_NOT_DEFINED
17#ifdef _GNU_SOURCE_WAS_NOT_DEFINED
38 n_log(
LOG_ERR,
"Could not allocate the internal hash table because it's already done");
47 n_log(
LOG_ERR,
"Could not allocate the internal hash with size %d", max);
50 n_log(
LOG_DEBUG,
"LOGGING: nodup system activated with a hash table of %d cells", max);
81static char*
get_nodup_key(
const char* file,
const char* func,
int line) {
102 nstrprintf(nstr,
"%s%s%s%d", file, func, prefix, line);
189void _n_nodup_log(
int LEVEL,
const char* file,
const char* func,
int line,
const char* format, ...) {
197 char* syslogbuffer = NULL;
199 va_start(args, format);
200 if (
vasprintf(&syslogbuffer, format, args) == -1) {
202 n_log(
LOG_ERR,
"=>%s:%s:%d unable to parse '%s', %s", file, func, line, format, strerror(error));
215 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
228 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
233 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
251void _n_nodup_log_indexed(
int LEVEL,
const char* prefix,
const char* file,
const char* func,
int line,
const char* format, ...) {
255 char* syslogbuffer = NULL;
257 va_start(args, format);
258 if (
vasprintf(&syslogbuffer, format, args) == -1) {
260 n_log(
LOG_ERR,
"=>%s:%s:%d unable to parse '%s:%s', %s", file, func, line, prefix, format, strerror(error));
273 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
286 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
291 _n_log(LEVEL, file, func, line,
"%s", syslogbuffer);
313 char* tmpfile = NULL;
317 n_log(
LOG_ERR,
"could not create tmp file name from filename %s",
_str(file));
321 int fd = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600);
323 n_log(
LOG_ERR,
"could not create file %s with 0600 permissions",
_str(tmpfile));
328 out = fdopen(fd,
"wb");
342 if (rename(tmpfile, file) != 0) {
344 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.
#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.