odyssey/sources/error.h

73 lines
1.5 KiB
C
Raw Normal View History

#ifndef ODYSSEY_ERROR_H
#define ODYSSEY_ERROR_H
/*
2018-03-12 14:03:15 +00:00
* Odyssey.
*
2018-04-04 13:19:58 +00:00
* Scalable PostgreSQL connection pooler.
*/
typedef struct od_error od_error_t;
2020-07-08 06:26:17 +00:00
#define OD_ERROR_MAX_LEN 256
struct od_error
{
char file[256];
int file_len;
char function[128];
int function_len;
2020-07-08 06:26:17 +00:00
char error[OD_ERROR_MAX_LEN];
int error_len;
int line;
};
static inline void
od_error_init(od_error_t *error)
{
error->file[0] = 0;
error->file_len = 0;
error->function[0] = 0;
error->function_len = 0;
error->error[0] = 0;
error->error_len = 0;
error->line = 0;
}
static inline void
od_error_setv(od_error_t *error,
const char *file,
const char *function,
int line,
char *fmt,
va_list args)
{
error->file_len = od_snprintf(error->file, sizeof(error->file), "%s", file);
error->function_len =
od_snprintf(error->function, sizeof(error->function), "%s", function);
error->line = line;
int len;
len = od_vsnprintf(error->error, sizeof(error->error), fmt, args);
error->error_len = len;
}
static inline int
od_error_set(od_error_t *error,
const char *file,
const char *function,
int line,
char *fmt,
...)
{
va_list args;
va_start(args, fmt);
od_error_setv(error, file, function, line, fmt, args);
va_end(args);
return -1;
}
#define od_errorf(error, fmt, ...) \
od_error_set(error, __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
#endif /* ODYSSEY_ERROR_H */