mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 17:49:13 +00:00
Run 'make indent' on 'flog/'
Separate commit for easier criu-dev <-> master transfer. Acked-by: Mike Rapoport <rppt@linux.ibm.com> Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
parent
1444b72d25
commit
cc193dc669
7 changed files with 153 additions and 165 deletions
|
|
@ -8,64 +8,70 @@
|
|||
*/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
|
||||
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
|
||||
|
||||
#define __stringify_1(x...) #x
|
||||
#define __stringify(x...) __stringify_1(x)
|
||||
#define __stringify_1(x...) #x
|
||||
#define __stringify(x...) __stringify_1(x)
|
||||
|
||||
#define NORETURN __attribute__((__noreturn__))
|
||||
#define __packed __attribute__((__packed__))
|
||||
#define __used __attribute__((__used__))
|
||||
#define __maybe_unused __attribute__((unused))
|
||||
#define __always_unused __attribute__((unused))
|
||||
#define NORETURN __attribute__((__noreturn__))
|
||||
#define __packed __attribute__((__packed__))
|
||||
#define __used __attribute__((__used__))
|
||||
#define __maybe_unused __attribute__((unused))
|
||||
#define __always_unused __attribute__((unused))
|
||||
|
||||
#define __section(S) __attribute__ ((__section__(#S)))
|
||||
#define __section(S) __attribute__((__section__(#S)))
|
||||
|
||||
#ifndef __always_inline
|
||||
# define __always_inline inline __attribute__((always_inline))
|
||||
#define __always_inline inline __attribute__((always_inline))
|
||||
#endif
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#ifndef always_inline
|
||||
# define always_inline __always_inline
|
||||
#define always_inline __always_inline
|
||||
#endif
|
||||
|
||||
#ifndef noinline
|
||||
# define noinline __attribute__((noinline))
|
||||
#define noinline __attribute__((noinline))
|
||||
#endif
|
||||
|
||||
#define __aligned(x) __attribute__((aligned(x)))
|
||||
#define __aligned(x) __attribute__((aligned(x)))
|
||||
|
||||
#ifndef offsetof
|
||||
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) & ((TYPE *)0)->MEMBER)
|
||||
#endif
|
||||
|
||||
#define barrier() asm volatile("" ::: "memory")
|
||||
#define barrier() asm volatile("" ::: "memory")
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const typeof(((type *)0)->member) *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
|
||||
#define __round_mask(x, y) ((__typeof__(x))((y) - 1))
|
||||
#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
|
||||
#define round_down(x, y) ((x) & ~__round_mask(x, y))
|
||||
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
||||
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
|
||||
#define round_up(x, y) ((((x)-1) | __round_mask(x, y)) + 1)
|
||||
#define round_down(x, y) ((x) & ~__round_mask(x, y))
|
||||
#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
|
||||
#define ALIGN(x, a) (((x) + (a)-1) & ~((a)-1))
|
||||
|
||||
#define min(x, y) ({ \
|
||||
typeof(x) _min1 = (x); \
|
||||
typeof(y) _min2 = (y); \
|
||||
(void) (&_min1 == &_min2); \
|
||||
_min1 < _min2 ? _min1 : _min2; })
|
||||
#define min(x, y) \
|
||||
({ \
|
||||
typeof(x) _min1 = (x); \
|
||||
typeof(y) _min2 = (y); \
|
||||
(void)(&_min1 == &_min2); \
|
||||
_min1 < _min2 ? _min1 : _min2; \
|
||||
})
|
||||
|
||||
#define max(x, y) ({ \
|
||||
typeof(x) _max1 = (x); \
|
||||
typeof(y) _max2 = (y); \
|
||||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
#define max(x, y) \
|
||||
({ \
|
||||
typeof(x) _max1 = (x); \
|
||||
typeof(y) _max2 = (y); \
|
||||
(void)(&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; \
|
||||
})
|
||||
|
||||
#define is_log2(v) (((v) & ((v) - 1)) == 0)
|
||||
#define is_log2(v) (((v) & ((v)-1)) == 0)
|
||||
|
||||
#endif /* __COMPILER_H__ */
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#define pr_out(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
|
||||
#define pr_out(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
|
||||
|
||||
#if 1
|
||||
# define pr_debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
||||
#define pr_debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
# define pr_debug(fmt, ...)
|
||||
#define pr_debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define pr_err(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define pr_perror(fmt, ...) fprintf(stderr, "Error (%s:%d): "fmt "%m\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define pr_err(fmt, ...) fprintf(stderr, "Error (%s:%d): " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define pr_perror(fmt, ...) fprintf(stderr, "Error (%s:%d): " fmt "%m\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#endif /* __LOG_H__ */
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef uint64_t u64;
|
||||
typedef int64_t s64;
|
||||
typedef uint32_t u32;
|
||||
typedef int32_t s32;
|
||||
typedef uint16_t u16;
|
||||
typedef int16_t s16;
|
||||
typedef uint8_t u8;
|
||||
typedef int8_t s8;
|
||||
typedef uint64_t u64;
|
||||
typedef int64_t s64;
|
||||
typedef uint32_t u32;
|
||||
typedef int32_t s32;
|
||||
typedef uint16_t u16;
|
||||
typedef int16_t s16;
|
||||
typedef uint8_t u8;
|
||||
typedef int8_t s8;
|
||||
|
||||
#endif /* __FLOG_TYPES_H__ */
|
||||
|
|
|
|||
|
|
@ -13,68 +13,59 @@
|
|||
/*
|
||||
* By Laurent Deniau at https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
|
||||
*/
|
||||
#define FLOG_PP_NARG_(...) FLOG_PP_ARG_N(__VA_ARGS__)
|
||||
#define FLOG_PP_NARG(...) FLOG_PP_NARG_(1, ##__VA_ARGS__, FLOG_PP_RSEQ_N())
|
||||
#define FLOG_PP_NARG_(...) FLOG_PP_ARG_N(__VA_ARGS__)
|
||||
#define FLOG_PP_NARG(...) FLOG_PP_NARG_(1, ##__VA_ARGS__, FLOG_PP_RSEQ_N())
|
||||
|
||||
#define FLOG_PP_ARG_N( _0, _1, _2, _3, _4, \
|
||||
_5, _6, _7, _8, _9, \
|
||||
_10,_11,_12,_13,_14, \
|
||||
_15,_16,_17,_18,_19, \
|
||||
_20,_21,_22,_23,_24, \
|
||||
_25,_26,_27,_28,_29, \
|
||||
_30,_31, N, ...) N
|
||||
#define FLOG_PP_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, N, ...) \
|
||||
N
|
||||
|
||||
#define FLOG_PP_RSEQ_N() \
|
||||
31, 30, 29, 28, 27, \
|
||||
26, 25, 24, 23, 22, \
|
||||
21, 20, 19, 18, 17, \
|
||||
16, 15, 14, 13, 12, \
|
||||
11, 10, 9, 8, 7, \
|
||||
6, 5, 4, 3, 2, \
|
||||
1, 0
|
||||
#define FLOG_PP_RSEQ_N() \
|
||||
31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, \
|
||||
2, 1, 0
|
||||
|
||||
#define FLOG_GENMASK_0(N, x) 0
|
||||
#define FLOG_GENMASK_1(N, op, x, ...) (op(N, 0, x))
|
||||
#define FLOG_GENMASK_2(N, op, x, ...) ((op(N, 1, x)) | FLOG_GENMASK_1(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_3(N, op, x, ...) ((op(N, 2, x)) | FLOG_GENMASK_2(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_4(N, op, x, ...) ((op(N, 3, x)) | FLOG_GENMASK_3(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_5(N, op, x, ...) ((op(N, 4, x)) | FLOG_GENMASK_4(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_6(N, op, x, ...) ((op(N, 5, x)) | FLOG_GENMASK_5(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_7(N, op, x, ...) ((op(N, 6, x)) | FLOG_GENMASK_6(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_8(N, op, x, ...) ((op(N, 7, x)) | FLOG_GENMASK_7(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_9(N, op, x, ...) ((op(N, 8, x)) | FLOG_GENMASK_8(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_10(N, op, x, ...) ((op(N, 9, x)) | FLOG_GENMASK_9(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_11(N, op, x, ...) ((op(N, 10, x)) | FLOG_GENMASK_10(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_12(N, op, x, ...) ((op(N, 11, x)) | FLOG_GENMASK_11(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_13(N, op, x, ...) ((op(N, 12, x)) | FLOG_GENMASK_12(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_14(N, op, x, ...) ((op(N, 13, x)) | FLOG_GENMASK_13(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_15(N, op, x, ...) ((op(N, 14, x)) | FLOG_GENMASK_14(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_16(N, op, x, ...) ((op(N, 15, x)) | FLOG_GENMASK_15(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_17(N, op, x, ...) ((op(N, 16, x)) | FLOG_GENMASK_16(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_18(N, op, x, ...) ((op(N, 17, x)) | FLOG_GENMASK_17(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_19(N, op, x, ...) ((op(N, 18, x)) | FLOG_GENMASK_18(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_20(N, op, x, ...) ((op(N, 19, x)) | FLOG_GENMASK_19(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_21(N, op, x, ...) ((op(N, 20, x)) | FLOG_GENMASK_20(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_22(N, op, x, ...) ((op(N, 21, x)) | FLOG_GENMASK_21(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_23(N, op, x, ...) ((op(N, 22, x)) | FLOG_GENMASK_22(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_24(N, op, x, ...) ((op(N, 23, x)) | FLOG_GENMASK_23(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_25(N, op, x, ...) ((op(N, 24, x)) | FLOG_GENMASK_24(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_26(N, op, x, ...) ((op(N, 25, x)) | FLOG_GENMASK_25(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_27(N, op, x, ...) ((op(N, 26, x)) | FLOG_GENMASK_26(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_28(N, op, x, ...) ((op(N, 27, x)) | FLOG_GENMASK_27(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_29(N, op, x, ...) ((op(N, 28, x)) | FLOG_GENMASK_28(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_30(N, op, x, ...) ((op(N, 29, x)) | FLOG_GENMASK_29(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_31(N, op, x, ...) ((op(N, 30, x)) | FLOG_GENMASK_30(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_32(N, op, x, ...) ((op(N, 31, x)) | FLOG_GENMASK_31(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_0(N, x) 0
|
||||
#define FLOG_GENMASK_1(N, op, x, ...) (op(N, 0, x))
|
||||
#define FLOG_GENMASK_2(N, op, x, ...) ((op(N, 1, x)) | FLOG_GENMASK_1(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_3(N, op, x, ...) ((op(N, 2, x)) | FLOG_GENMASK_2(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_4(N, op, x, ...) ((op(N, 3, x)) | FLOG_GENMASK_3(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_5(N, op, x, ...) ((op(N, 4, x)) | FLOG_GENMASK_4(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_6(N, op, x, ...) ((op(N, 5, x)) | FLOG_GENMASK_5(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_7(N, op, x, ...) ((op(N, 6, x)) | FLOG_GENMASK_6(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_8(N, op, x, ...) ((op(N, 7, x)) | FLOG_GENMASK_7(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_9(N, op, x, ...) ((op(N, 8, x)) | FLOG_GENMASK_8(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_10(N, op, x, ...) ((op(N, 9, x)) | FLOG_GENMASK_9(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_11(N, op, x, ...) ((op(N, 10, x)) | FLOG_GENMASK_10(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_12(N, op, x, ...) ((op(N, 11, x)) | FLOG_GENMASK_11(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_13(N, op, x, ...) ((op(N, 12, x)) | FLOG_GENMASK_12(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_14(N, op, x, ...) ((op(N, 13, x)) | FLOG_GENMASK_13(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_15(N, op, x, ...) ((op(N, 14, x)) | FLOG_GENMASK_14(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_16(N, op, x, ...) ((op(N, 15, x)) | FLOG_GENMASK_15(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_17(N, op, x, ...) ((op(N, 16, x)) | FLOG_GENMASK_16(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_18(N, op, x, ...) ((op(N, 17, x)) | FLOG_GENMASK_17(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_19(N, op, x, ...) ((op(N, 18, x)) | FLOG_GENMASK_18(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_20(N, op, x, ...) ((op(N, 19, x)) | FLOG_GENMASK_19(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_21(N, op, x, ...) ((op(N, 20, x)) | FLOG_GENMASK_20(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_22(N, op, x, ...) ((op(N, 21, x)) | FLOG_GENMASK_21(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_23(N, op, x, ...) ((op(N, 22, x)) | FLOG_GENMASK_22(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_24(N, op, x, ...) ((op(N, 23, x)) | FLOG_GENMASK_23(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_25(N, op, x, ...) ((op(N, 24, x)) | FLOG_GENMASK_24(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_26(N, op, x, ...) ((op(N, 25, x)) | FLOG_GENMASK_25(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_27(N, op, x, ...) ((op(N, 26, x)) | FLOG_GENMASK_26(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_28(N, op, x, ...) ((op(N, 27, x)) | FLOG_GENMASK_27(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_29(N, op, x, ...) ((op(N, 28, x)) | FLOG_GENMASK_28(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_30(N, op, x, ...) ((op(N, 29, x)) | FLOG_GENMASK_29(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_31(N, op, x, ...) ((op(N, 30, x)) | FLOG_GENMASK_30(N, op, __VA_ARGS__))
|
||||
#define FLOG_GENMASK_32(N, op, x, ...) ((op(N, 31, x)) | FLOG_GENMASK_31(N, op, __VA_ARGS__))
|
||||
|
||||
#define FLOG_CONCAT(arg1, arg2) FLOG_CONCAT1(arg1, arg2)
|
||||
#define FLOG_CONCAT1(arg1, arg2) FLOG_CONCAT2(arg1, arg2)
|
||||
#define FLOG_CONCAT2(arg1, arg2) arg1##arg2
|
||||
#define FLOG_CONCAT(arg1, arg2) FLOG_CONCAT1(arg1, arg2)
|
||||
#define FLOG_CONCAT1(arg1, arg2) FLOG_CONCAT2(arg1, arg2)
|
||||
#define FLOG_CONCAT2(arg1, arg2) arg1##arg2
|
||||
|
||||
#define FLOG_GENMASK_(N, op, ...) FLOG_CONCAT(FLOG_GENMASK_, N)(N, op, ##__VA_ARGS__)
|
||||
#define FLOG_GENMASK(op, ...) FLOG_GENMASK_(FLOG_PP_NARG(__VA_ARGS__), op, ##__VA_ARGS__)
|
||||
#define FLOG_GENMASK_(N, op, ...) FLOG_CONCAT(FLOG_GENMASK_, N)(N, op, ##__VA_ARGS__)
|
||||
#define FLOG_GENMASK(op, ...) FLOG_GENMASK_(FLOG_PP_NARG(__VA_ARGS__), op, ##__VA_ARGS__)
|
||||
|
||||
#define flog_genbit(ord, n, v, ...) \
|
||||
#define flog_genbit(ord, n, v, ...) \
|
||||
_Generic((v), \
|
||||
\
|
||||
/* Basic types */ \
|
||||
|
|
@ -127,21 +118,20 @@
|
|||
default: -1)
|
||||
|
||||
typedef struct {
|
||||
unsigned int magic;
|
||||
unsigned int size;
|
||||
unsigned int nargs;
|
||||
unsigned int mask;
|
||||
long fmt;
|
||||
long args[0];
|
||||
unsigned int magic;
|
||||
unsigned int size;
|
||||
unsigned int nargs;
|
||||
unsigned int mask;
|
||||
long fmt;
|
||||
long args[0];
|
||||
} flog_msg_t;
|
||||
|
||||
extern int flog_encode_msg(int fdout, unsigned int nargs, unsigned int mask, const char *format, ...);
|
||||
void flog_decode_msg(int fdout, const char *format, ...);
|
||||
extern int flog_decode_all(int fdin, int fdout);
|
||||
|
||||
#define flog_encode(fdout, fmt, ...) \
|
||||
flog_encode_msg(fdout, FLOG_PP_NARG(__VA_ARGS__), \
|
||||
FLOG_GENMASK(flog_genbit, ##__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
#define flog_encode(fdout, fmt, ...) \
|
||||
flog_encode_msg(fdout, FLOG_PP_NARG(__VA_ARGS__), FLOG_GENMASK(flog_genbit, ##__VA_ARGS__), fmt, ##__VA_ARGS__)
|
||||
|
||||
int flog_map_buf(int fdout);
|
||||
int flog_close(int fdout);
|
||||
|
|
|
|||
|
|
@ -7,31 +7,35 @@
|
|||
#include "log.h"
|
||||
#include "types.h"
|
||||
|
||||
#define __xalloc(op, size, ...) \
|
||||
({ \
|
||||
void *___p = op(__VA_ARGS__); \
|
||||
___p; \
|
||||
#define __xalloc(op, size, ...) \
|
||||
({ \
|
||||
void *___p = op(__VA_ARGS__); \
|
||||
___p; \
|
||||
})
|
||||
|
||||
#define xstrdup(str) __xalloc(strdup, strlen(str) + 1, str)
|
||||
#define xmalloc(size) __xalloc(malloc, size, size)
|
||||
#define xzalloc(size) __xalloc(calloc, size, 1, size)
|
||||
#define xrealloc(p, size) __xalloc(realloc, size, p, size)
|
||||
#define xstrdup(str) __xalloc(strdup, strlen(str) + 1, str)
|
||||
#define xmalloc(size) __xalloc(malloc, size, size)
|
||||
#define xzalloc(size) __xalloc(calloc, size, 1, size)
|
||||
#define xrealloc(p, size) __xalloc(realloc, size, p, size)
|
||||
|
||||
#define xfree(p) do { if (p) free(p); } while (0)
|
||||
#define xfree(p) \
|
||||
do { \
|
||||
if (p) \
|
||||
free(p); \
|
||||
} while (0)
|
||||
|
||||
#define xrealloc_safe(pptr, size) \
|
||||
({ \
|
||||
int __ret = -ENOMEM; \
|
||||
void *new = xrealloc(*pptr, size); \
|
||||
if (new) { \
|
||||
*pptr = new; \
|
||||
__ret = 0; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
#define xrealloc_safe(pptr, size) \
|
||||
({ \
|
||||
int __ret = -ENOMEM; \
|
||||
void *new = xrealloc(*pptr, size); \
|
||||
if (new) { \
|
||||
*pptr = new; \
|
||||
__ret = 0; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#define memzero_p(p) memset(p, 0, sizeof(*p))
|
||||
#define memzero(p, size) memset(p, 0, size)
|
||||
#define memzero_p(p) memset(p, 0, sizeof(*p))
|
||||
#define memzero(p, size) memset(p, 0, size)
|
||||
|
||||
#endif /* __UTIL_H__ */
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define MAGIC 0xABCDABCD
|
||||
|
||||
#define BUF_SIZE (1<<20)
|
||||
#define BUF_SIZE (1 << 20)
|
||||
static char _mbuf[BUF_SIZE];
|
||||
static char *mbuf = _mbuf;
|
||||
static char *fbuf;
|
||||
|
|
@ -119,11 +119,10 @@ int flog_map_buf(int fdout)
|
|||
}
|
||||
|
||||
if (!fbuf)
|
||||
addr = mmap(NULL, BUF_SIZE * 2, PROT_WRITE | PROT_READ,
|
||||
MAP_FILE | MAP_SHARED, fdout, fsize - 2 * BUF_SIZE);
|
||||
addr = mmap(NULL, BUF_SIZE * 2, PROT_WRITE | PROT_READ, MAP_FILE | MAP_SHARED, fdout,
|
||||
fsize - 2 * BUF_SIZE);
|
||||
else
|
||||
addr = mremap(fbuf + BUF_SIZE, BUF_SIZE,
|
||||
BUF_SIZE * 2, MREMAP_FIXED, fbuf);
|
||||
addr = mremap(fbuf + BUF_SIZE, BUF_SIZE, BUF_SIZE * 2, MREMAP_FIXED, fbuf);
|
||||
if (addr == MAP_FAILED) {
|
||||
fprintf(stderr, "Unable to map a buffer: %m");
|
||||
return -1;
|
||||
|
|
@ -160,7 +159,7 @@ int flog_encode_msg(int fdout, unsigned int nargs, unsigned int mask, const char
|
|||
if (mbuf != _mbuf && flog_map_buf(fdout))
|
||||
return -1;
|
||||
|
||||
m = (void *) mbuf;
|
||||
m = (void *)mbuf;
|
||||
|
||||
m->nargs = nargs;
|
||||
m->mask = mask;
|
||||
|
|
|
|||
|
|
@ -33,12 +33,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
static const char short_opts[] = "m:o:di:h";
|
||||
static struct option long_opts[] = {
|
||||
{ "mode", required_argument, 0, 'm' },
|
||||
{ "output", required_argument, 0, 'o' },
|
||||
{ "decode", no_argument, 0, 'd' },
|
||||
{ "iter", required_argument, 0, 'i' },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ },
|
||||
{ "mode", required_argument, 0, 'm' }, { "output", required_argument, 0, 'o' },
|
||||
{ "decode", no_argument, 0, 'd' }, { "iter", required_argument, 0, 'i' },
|
||||
{ "help", no_argument, 0, 'h' }, {},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
|
|
@ -68,8 +65,7 @@ int main(int argc, char *argv[])
|
|||
} else {
|
||||
fdout = open(optarg, O_RDWR | O_CREAT | O_TRUNC, 0644);
|
||||
if (fdout < 0) {
|
||||
fprintf(stderr, "Can't open %s: %s\n",
|
||||
optarg, strerror(errno));
|
||||
fprintf(stderr, "Can't open %s: %s\n", optarg, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -94,42 +90,35 @@ int main(int argc, char *argv[])
|
|||
if (fdout != STDOUT_FILENO && flog_map_buf(fdout))
|
||||
return 1;
|
||||
for (i = 0; i < niter; i++)
|
||||
if (flog_encode(fdout, "Some message %s %s %c %li %d %lu\n",
|
||||
str1, str2, 'c', (long)-4, (short)2,
|
||||
(unsigned long)2))
|
||||
if (flog_encode(fdout, "Some message %s %s %c %li %d %lu\n", str1, str2, 'c', (long)-4,
|
||||
(short)2, (unsigned long)2))
|
||||
return 1;
|
||||
if (flog_close(fdout))
|
||||
return 1;
|
||||
break;
|
||||
case MODE_DPRINTF:
|
||||
{
|
||||
break;
|
||||
case MODE_DPRINTF: {
|
||||
for (i = 0; i < niter; i++) {
|
||||
dprintf(fdout, "Some message %s %s %c %li %d %lu\n",
|
||||
str1, str2, 'c', (long)-4, (short)2,
|
||||
dprintf(fdout, "Some message %s %s %c %li %d %lu\n", str1, str2, 'c', (long)-4, (short)2,
|
||||
(unsigned long)2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MODE_FPRINTF:
|
||||
{
|
||||
case MODE_FPRINTF: {
|
||||
FILE *f = fdopen(fdout, "w");
|
||||
|
||||
for (i = 0; i < niter; i++) {
|
||||
fprintf(f, "Some message %s %s %c %li %d %lu\n",
|
||||
str1, str2, 'c', (long)-4, (short)2,
|
||||
fprintf(f, "Some message %s %s %c %li %d %lu\n", str1, str2, 'c', (long)-4, (short)2,
|
||||
(unsigned long)2);
|
||||
fflush(f);
|
||||
}
|
||||
fclose(f);
|
||||
break;
|
||||
}
|
||||
case MODE_SPRINTF:
|
||||
{
|
||||
case MODE_SPRINTF: {
|
||||
static char buf[4096];
|
||||
|
||||
for (i = 0; i < niter; i++) {
|
||||
sprintf(buf, "Some message %s %s %c %li %d %lu\n",
|
||||
str1, str2, 'c', (long)-4, (short)2,
|
||||
sprintf(buf, "Some message %s %s %c %li %d %lu\n", str1, str2, 'c', (long)-4, (short)2,
|
||||
(unsigned long)2);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue