Skip to content
Snippets Groups Projects
Commit 45558016 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Refactored common.h macros usage, temporary fixes for name clashes.

parent d7cb38bb
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,11 @@
//#define MEM_NOSLAB
//#define MEM_POISON
/* Eliminate compiler warning with unused parameters. */
#ifndef UNUSED
#define UNUSED(param) (void)(param)
#endif
/* Optimisation macros. */
#ifndef likely
#define likely(x) __builtin_expect((x),1)
......
......@@ -11,17 +11,20 @@
#ifndef _KNOT_DNSLIB_COMMON_H_
#define _KNOT_DNSLIB_COMMON_H_
#define PROJECT_NAME "dnslib" // Project name
#define PROJECT_VER 0x000100 // 0xMMIIRR (MAJOR,MINOR,REVISION)
#define DNSLIB_NAME "dnslib" // Project name
#define DNSLIB_VER 0x000100 // 0xMMIIRR (MAJOR,MINOR,REVISION)
typedef unsigned int uint;
/* Common macros.
*/
/*! \todo Refactor theese. We should have an allocator function handling this.*/
#ifndef ERR_ALLOC_FAILED
#define ERR_ALLOC_FAILED fprintf(stderr, "Allocation failed at %s:%d (%s ver.%x)\n", \
__FILE__, __LINE__, PROJECT_NAME, PROJECT_VER)
__FILE__, __LINE__, DNSLIB_NAME, DNSLIB_VER)
#endif
#ifndef CHECK_ALLOC_LOG
#define CHECK_ALLOC_LOG(var, ret) \
do { \
if ((var) == NULL) { \
......@@ -29,20 +32,32 @@ typedef unsigned int uint;
return (ret); \
} \
} while (0)
#endif
#ifndef CHECK_ALLOC
#define CHECK_ALLOC(var, ret) \
do { \
if ((var) == NULL) { \
return (ret); \
} \
} while (0)
#endif
/* Eliminate compiler warning with unused parameters. */
#define UNUSED(param) (param) = (param)
#ifndef UNUSED
#define UNUSED(param) (void)(param)
#endif
/* Type-safe minimum and maximum macros. */
#ifndef MIN
#define MIN(a, b) \
({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
#endif
/* Minimum and maximum macros. */
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#ifndef MAX
#define MAX(a, b) \
({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
#endif
/* Optimisation macros. */
#ifndef likely
......
......@@ -1069,9 +1069,9 @@ int zone_dump_text(dnslib_zone_t *zone, const char *filename)
}
fprintf(f, ";Dumped using %s v. %d.%d.%d\n", PROJECT_NAME,
PROJECT_VER / 10000,
(PROJECT_VER / 100) % 100,
PROJECT_VER % 100);
DNSLIB_VER / 10000,
(DNSLIB_VER / 100) % 100,
DNSLIB_VER % 100);
struct dump_param param;
param.f = f;
......
......@@ -19,8 +19,6 @@
/* Common types and constants.
*/
typedef unsigned int uint;
#define PROJECT_NAME PACKAGE // Project name
#define PROJECT_VER 0x000100 // 0xMMIIRR (MAJOR,MINOR,REVISION)
#define PROJECT_EXEC "knotd" // Project executable
......@@ -50,37 +48,24 @@ typedef unsigned int uint;
#include "common/print.h"
#include "knot/other/log.h"
#include "knot/other/debug.h"
#include "dnslib/dnslib-common.h"
/* Common macros.
*/
#define ERR_ALLOC_FAILED log_server_error("Allocation failed at %s:%d (%s ver.%x)\n", \
__FILE__, __LINE__, PROJECT_NAME, PROJECT_VER)
#define CHECK_ALLOC_LOG(var, ret) \
do { \
if ((var) == NULL) { \
ERR_ALLOC_FAILED; \
return (ret); \
} \
} while (0)
#define CHECK_ALLOC(var, ret) \
do { \
if ((var) == NULL) { \
return (ret); \
} \
} while (0)
/* Eliminate compiler warning with unused parameters. */
#ifndef UNUSED
#define UNUSED(param) (void)(param)
#endif
/* Type-safe minimum and maximum macros. */
#ifndef MIN
#define MIN(a, b) \
({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
#endif
#ifndef MAX
#define MAX(a, b) \
({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
#endif
/* Optimisation macros. */
#ifndef likely
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment