Skip to content

Commit 8e19594

Browse files
committed
Indent pre-processor directives
To make nested ifs easier to read
1 parent d5bc7cb commit 8e19594

File tree

6 files changed

+194
-193
lines changed

6 files changed

+194
-193
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ IndentWidth: 4
33
BinPackArguments: false
44
BinPackParameters: false
55
IndentCaseLabels: true
6+
IndentPPDirectives: BeforeHash

bin/mmdblookup.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#ifndef _POSIX_C_SOURCE
2-
#define _POSIX_C_SOURCE 200809L
2+
#define _POSIX_C_SOURCE 200809L
33
#endif
44

55
#ifdef HAVE_CONFIG_H
6-
#include <config.h>
6+
#include <config.h>
77
#endif
88
#include "maxminddb.h"
99
#include <errno.h>
1010
#include <getopt.h>
1111
#ifndef _WIN32
12-
#include <pthread.h>
12+
#include <pthread.h>
1313
#endif
1414
#include <limits.h>
1515
#include <stdbool.h>
@@ -19,13 +19,13 @@
1919
#include <time.h>
2020

2121
#ifdef _WIN32
22-
#ifndef UNICODE
23-
#define UNICODE
24-
#endif
25-
#include <malloc.h>
22+
#ifndef UNICODE
23+
#define UNICODE
24+
#endif
25+
#include <malloc.h>
2626
#else
27-
#include <libgen.h>
28-
#include <unistd.h>
27+
#include <libgen.h>
28+
#include <unistd.h>
2929
#endif
3030

3131
static void usage(char *program, int exit_code, const char *error);
@@ -718,28 +718,28 @@ static bool start_threaded_benchmark(MMDB_s *const mmdb,
718718

719719
static long double get_time(void) {
720720
// clock_gettime() is not present on OSX until 10.12.
721-
#ifdef HAVE_CLOCK_GETTIME
721+
#ifdef HAVE_CLOCK_GETTIME
722722
struct timespec tp = {
723723
.tv_sec = 0,
724724
.tv_nsec = 0,
725725
};
726726
clockid_t clk_id = CLOCK_REALTIME;
727-
#ifdef _POSIX_MONOTONIC_CLOCK
727+
#ifdef _POSIX_MONOTONIC_CLOCK
728728
clk_id = CLOCK_MONOTONIC;
729-
#endif
729+
#endif
730730
if (clock_gettime(clk_id, &tp) != 0) {
731731
fprintf(stderr, "clock_gettime(): %s\n", strerror(errno));
732732
return -1;
733733
}
734734
return (long double)tp.tv_sec + ((float)tp.tv_nsec / 1e9);
735-
#else
735+
#else
736736
time_t t = time(NULL);
737737
if (t == (time_t)-1) {
738738
fprintf(stderr, "time(): %s\n", strerror(errno));
739739
return -1;
740740
}
741741
return (long double)t;
742-
#endif
742+
#endif
743743
}
744744

745745
static void *thread(void *arg) {

include/maxminddb.h

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,97 @@ extern "C" {
33
#endif
44

55
#ifndef MAXMINDDB_H
6-
#define MAXMINDDB_H
6+
#define MAXMINDDB_H
77

8-
#include "maxminddb_config.h"
9-
#include <stdarg.h>
10-
#include <stdbool.h>
11-
#include <stdint.h>
12-
#include <stdio.h>
13-
#include <sys/types.h>
8+
#include "maxminddb_config.h"
9+
#include <stdarg.h>
10+
#include <stdbool.h>
11+
#include <stdint.h>
12+
#include <stdio.h>
13+
#include <sys/types.h>
1414

15-
#ifdef __has_include
16-
#if __has_include(<endian.h>)
17-
#include <endian.h>
18-
#elif __has_include(<sys/endian.h>)
19-
#include <sys/endian.h>
20-
#endif
21-
#endif
15+
#ifdef __has_include
16+
#if __has_include(<endian.h>)
17+
#include <endian.h>
18+
#elif __has_include(<sys/endian.h>)
19+
#include <sys/endian.h>
20+
#endif
21+
#endif
2222

23-
#ifdef _WIN32
24-
#include <winsock2.h>
25-
#include <ws2tcpip.h>
26-
/* libmaxminddb package version from configure */
23+
#ifdef _WIN32
24+
#include <winsock2.h>
25+
#include <ws2tcpip.h>
26+
/* libmaxminddb package version from configure */
2727

28-
#if defined(_MSC_VER)
29-
/* MSVC doesn't define signed size_t, copy it from configure */
30-
#define ssize_t SSIZE_T
28+
#if defined(_MSC_VER)
29+
/* MSVC doesn't define signed size_t, copy it from configure */
30+
#define ssize_t SSIZE_T
3131

32-
#endif
33-
#else
34-
#include <netdb.h>
35-
#include <netinet/in.h>
36-
#include <sys/socket.h>
37-
#endif
32+
#endif
33+
#else
34+
#include <netdb.h>
35+
#include <netinet/in.h>
36+
#include <sys/socket.h>
37+
#endif
3838

39-
#if !defined(MMDB_LITTLE_ENDIAN)
40-
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
41-
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
42-
#define MMDB_LITTLE_ENDIAN 1
43-
#endif
44-
#elif defined(_WIN32) || defined(_WIN64)
45-
// We assume modern Windows targets are little endian
46-
#define MMDB_LITTLE_ENDIAN 1
47-
#endif
48-
#endif
39+
#if !defined(MMDB_LITTLE_ENDIAN)
40+
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
41+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
42+
#define MMDB_LITTLE_ENDIAN 1
43+
#endif
44+
#elif defined(_WIN32) || defined(_WIN64)
45+
// We assume modern Windows targets are little endian
46+
#define MMDB_LITTLE_ENDIAN 1
47+
#endif
48+
#endif
4949

50-
#define MMDB_DATA_TYPE_EXTENDED (0)
51-
#define MMDB_DATA_TYPE_POINTER (1)
52-
#define MMDB_DATA_TYPE_UTF8_STRING (2)
53-
#define MMDB_DATA_TYPE_DOUBLE (3)
54-
#define MMDB_DATA_TYPE_BYTES (4)
55-
#define MMDB_DATA_TYPE_UINT16 (5)
56-
#define MMDB_DATA_TYPE_UINT32 (6)
57-
#define MMDB_DATA_TYPE_MAP (7)
58-
#define MMDB_DATA_TYPE_INT32 (8)
59-
#define MMDB_DATA_TYPE_UINT64 (9)
60-
#define MMDB_DATA_TYPE_UINT128 (10)
61-
#define MMDB_DATA_TYPE_ARRAY (11)
62-
#define MMDB_DATA_TYPE_CONTAINER (12)
63-
#define MMDB_DATA_TYPE_END_MARKER (13)
64-
#define MMDB_DATA_TYPE_BOOLEAN (14)
65-
#define MMDB_DATA_TYPE_FLOAT (15)
50+
#define MMDB_DATA_TYPE_EXTENDED (0)
51+
#define MMDB_DATA_TYPE_POINTER (1)
52+
#define MMDB_DATA_TYPE_UTF8_STRING (2)
53+
#define MMDB_DATA_TYPE_DOUBLE (3)
54+
#define MMDB_DATA_TYPE_BYTES (4)
55+
#define MMDB_DATA_TYPE_UINT16 (5)
56+
#define MMDB_DATA_TYPE_UINT32 (6)
57+
#define MMDB_DATA_TYPE_MAP (7)
58+
#define MMDB_DATA_TYPE_INT32 (8)
59+
#define MMDB_DATA_TYPE_UINT64 (9)
60+
#define MMDB_DATA_TYPE_UINT128 (10)
61+
#define MMDB_DATA_TYPE_ARRAY (11)
62+
#define MMDB_DATA_TYPE_CONTAINER (12)
63+
#define MMDB_DATA_TYPE_END_MARKER (13)
64+
#define MMDB_DATA_TYPE_BOOLEAN (14)
65+
#define MMDB_DATA_TYPE_FLOAT (15)
6666

67-
#define MMDB_RECORD_TYPE_SEARCH_NODE (0)
68-
#define MMDB_RECORD_TYPE_EMPTY (1)
69-
#define MMDB_RECORD_TYPE_DATA (2)
70-
#define MMDB_RECORD_TYPE_INVALID (3)
67+
#define MMDB_RECORD_TYPE_SEARCH_NODE (0)
68+
#define MMDB_RECORD_TYPE_EMPTY (1)
69+
#define MMDB_RECORD_TYPE_DATA (2)
70+
#define MMDB_RECORD_TYPE_INVALID (3)
7171

72-
/* flags for open */
73-
#define MMDB_MODE_MMAP (1)
74-
#define MMDB_MODE_MASK (7)
72+
/* flags for open */
73+
#define MMDB_MODE_MMAP (1)
74+
#define MMDB_MODE_MASK (7)
7575

76-
/* error codes */
77-
#define MMDB_SUCCESS (0)
78-
#define MMDB_FILE_OPEN_ERROR (1)
79-
#define MMDB_CORRUPT_SEARCH_TREE_ERROR (2)
80-
#define MMDB_INVALID_METADATA_ERROR (3)
81-
#define MMDB_IO_ERROR (4)
82-
#define MMDB_OUT_OF_MEMORY_ERROR (5)
83-
#define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6)
84-
#define MMDB_INVALID_DATA_ERROR (7)
85-
#define MMDB_INVALID_LOOKUP_PATH_ERROR (8)
86-
#define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9)
87-
#define MMDB_INVALID_NODE_NUMBER_ERROR (10)
88-
#define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11)
76+
/* error codes */
77+
#define MMDB_SUCCESS (0)
78+
#define MMDB_FILE_OPEN_ERROR (1)
79+
#define MMDB_CORRUPT_SEARCH_TREE_ERROR (2)
80+
#define MMDB_INVALID_METADATA_ERROR (3)
81+
#define MMDB_IO_ERROR (4)
82+
#define MMDB_OUT_OF_MEMORY_ERROR (5)
83+
#define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6)
84+
#define MMDB_INVALID_DATA_ERROR (7)
85+
#define MMDB_INVALID_LOOKUP_PATH_ERROR (8)
86+
#define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9)
87+
#define MMDB_INVALID_NODE_NUMBER_ERROR (10)
88+
#define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11)
8989

90-
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
91-
#if MMDB_UINT128_USING_MODE
90+
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
91+
#if MMDB_UINT128_USING_MODE
9292
typedef unsigned int mmdb_uint128_t __attribute__((__mode__(TI)));
93-
#else
93+
#else
9494
typedef unsigned __int128 mmdb_uint128_t;
95-
#endif
96-
#endif
95+
#endif
96+
#endif
9797

9898
/* This is a pointer into the data section for a given IP address lookup */
9999
typedef struct MMDB_entry_s {
@@ -118,11 +118,11 @@ typedef struct MMDB_entry_data_s {
118118
uint32_t uint32;
119119
int32_t int32;
120120
uint64_t uint64;
121-
#if MMDB_UINT128_IS_BYTE_ARRAY
121+
#if MMDB_UINT128_IS_BYTE_ARRAY
122122
uint8_t uint128[16];
123-
#else
123+
#else
124124
mmdb_uint128_t uint128;
125-
#endif
125+
#endif
126126
bool boolean;
127127
float float_value;
128128
};

0 commit comments

Comments
 (0)