forked from cheekyguy/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric.h
113 lines (90 loc) · 2.47 KB
/
generic.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/**
* this file defines types that are used in multiple places, yet don't belong to
* any one particular module.
*/
#if !defined(_generic_h_)
#define _generic_h_
/* this needs to go on top. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/**
* Start including stuff to get type definitions. Some will depend on config.h.
*/
/* Get a consistent bool type */
#if HAVE_STDBOOL_H
# include <stdbool.h>
#else
typedef enum {false = 0, true = 1} bool;
#endif
#if HAVE_STDINT_H
# include <stdint.h>
#else
typedef unsigned char uint8_t;
#endif
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#else
typedef unsigned char u_char;
#endif
/* some POSIX systems need the following definition
* to get mlockall flags out of sys/mman.h. */
#ifndef _P1003_1B_VISIBLE
#define _P1003_1B_VISIBLE
#endif
#include <sys/mman.h>
/**
* Declare simple types (enums, typedefs of native types).
*/
#if __WORDSIZE == 64
#define PRINTF_INT64_MODIFIER "l"
#else
#define PRINTF_INT64_MODIFIER "ll"
#endif
/** Time relative to server start. Smaller than time_t on 64-bit systems. */
typedef unsigned int rel_time_t;
/**
* Start including stuff to get other header files.
*/
#ifdef HAVE_MALLOC_H
/* OpenBSD has a malloc.h, but warns to use stdlib.h instead */
#ifndef __OpenBSD__
#include <malloc.h>
#endif
#endif
/* unistd.h is here */
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/*
* IOV_MAX comes from stdio.h. Make sure we include it before we try to define
* it ourselves.
*/
/* need this to get IOV_MAX on some platforms. */
#ifndef __need_IOV_MAX
#define __need_IOV_MAX
#endif
#include <stdio.h>
#include <limits.h>
/* FreeBSD 4.x doesn't have IOV_MAX exposed. */
#ifndef IOV_MAX
#if defined(__FreeBSD__)
# define IOV_MAX 1024
#endif
#endif
#include <stdarg.h>
/* create an always_assert macro for tests that are so cheap that they should
* always be performed, regardless of NDEBUG */
#if defined(NDEBUG)
#define always_assert(condition) if (! (condition)) { fprintf(stderr, "%s\n", #condition); abort(); }
#else
#define always_assert assert
#endif /* #if defined(NDEBUG) */
#define DECL_MT_FUNC(ret_type, func_name, args) extern ret_type do_ ## func_name args; extern ret_type func_name args;
// bump a counter up by one. return 0 if the counter has overflowed, nonzero otherwise.
#define BUMP(cntr) ((++(cntr)) != 0)
#endif /* #if !defined(_generic_h_) */