Skip to content

Commit 828dc4e

Browse files
committed
treewide: replace include guards with pragma once
An alternative to include guards using `#ifndef`, `#define` and `#endif` is `#pragma once`. This non-standard but commonly supported directive among C and C++ compilers, it also requires less code and does not require the definition of a variable with risk of name conflicts. Also, the variable definitions often deviate after file renaming and/or move. Bonus, the use of `#pragma once` may improve compilation speed since it is a higher-level mechanism. The compiler itself can compare filenames or inodes without having to invoke the C preprocessor to resolve `#ifndef` and `#endif`. Signed-off-by: Robin Jarry <[email protected]>
1 parent 12a0792 commit 828dc4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+67
-268
lines changed

api/gr_api.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_API
5-
#define _GR_API
4+
#pragma once
65

76
#include <stdbool.h>
87
#include <stddef.h>
@@ -68,5 +67,3 @@ struct gr_api_event {
6867
};
6968

7069
int gr_api_client_event_recv(const struct gr_api_client *, struct gr_api_event **);
71-
72-
#endif

api/gr_api_client_impl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
// This file must be included in *one* of your client application files.
55

6-
#ifndef _GR_API_CLIENT_IMPL
7-
#define _GR_API_CLIENT_IMPL
6+
#pragma once
87

98
#include <gr_api.h>
109
#include <gr_macro.h>
@@ -161,5 +160,3 @@ int gr_api_client_event_recv(const struct gr_api_client *c, struct gr_api_event
161160
*event = NULL;
162161
return -errno;
163162
}
164-
165-
#endif

api/gr_bitops.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_BITOPS
5-
#define _GR_BITOPS
4+
#pragma once
65

76
#include <stdint.h>
87

98
#define GR_BIT8(n) (UINT8_C(1) << (n))
109
#define GR_BIT16(n) (UINT16_C(1) << (n))
1110
#define GR_BIT32(n) (UINT32_C(1) << (n))
1211
#define GR_BIT64(n) (UINT64_C(1) << (n))
13-
14-
#endif

api/gr_clock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2025 Robin Jarry
33

4-
#ifndef _GR_CLOCK
5-
#define _GR_CLOCK
4+
#pragma once
65

76
#include <stdint.h>
87
#include <time.h>
@@ -19,5 +18,3 @@ static inline clock_t gr_clock_us(void) {
1918
struct timespec tp = gr_clock_raw();
2019
return (tp.tv_sec * CLOCKS_PER_SEC) + (tp.tv_nsec / 1000);
2120
}
22-
23-
#endif

api/gr_errno.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_API_ERRNO
5-
#define _GR_API_ERRNO
4+
#pragma once
65

76
#include <errno.h>
87
#include <stddef.h>
@@ -16,5 +15,3 @@ static inline void *errno_set_null(int errnum) {
1615
errno = errnum;
1716
return NULL;
1817
}
19-
20-
#endif

api/gr_macro.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_MACRO
5-
#define _GR_MACRO
4+
#pragma once
65

76
#include <errno.h>
87

@@ -37,5 +36,3 @@
3736
} \
3837
n += __s; \
3938
} while (0)
40-
41-
#endif

api/gr_net_compat.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_NET_COMPAT
5-
#define _GR_NET_COMPAT
4+
#pragma once
65

76
#include <limits.h>
87
#include <stdint.h>
@@ -66,5 +65,3 @@ struct __attribute__((aligned(2))) rte_ether_addr {
6665
#define ICMP6_TYPE_ERR_PARAM_PROBLEM 4
6766
#define ICMP6_TYPE_ECHO_REQUEST 128
6867
#define ICMP6_TYPE_ECHO_REPLY 129
69-
70-
#endif

api/gr_net_types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_NET_TYPES
5-
#define _GR_NET_TYPES
4+
#pragma once
65

76
#include <gr_errno.h>
87

@@ -136,5 +135,3 @@ static inline int ip6_net_parse(const char *s, struct ip6_net *net, bool zero_ma
136135

137136
#define IP_ANY_RE "^(" __IPV4_RE "|" __IPV6_RE ")$"
138137
#define IP_ANY_NET_RE "^(" __IPV4_RE __IPV4_PREFIX_RE "|" __IPV6_RE __IPV6_PREFIX_RE "$"
139-
140-
#endif

api/gr_string.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Robin Jarry
33

4-
#ifndef _GR_STRING
5-
#define _GR_STRING
4+
#pragma once
65

76
#include <sched.h>
87
#include <stddef.h>
@@ -17,5 +16,3 @@ int cpuset_format(char *buf, size_t len, const cpu_set_t *set);
1716

1817
// Parse a list of CPUs (e.g. "0,1,3-9") to a cpu_set_t object.
1918
int cpuset_parse(cpu_set_t *set, const char *buf);
20-
21-
#endif

cli/complete.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2023 Robin Jarry
33

4-
#ifndef _GR_CLI_COMPLETE
5-
#define _GR_CLI_COMPLETE
4+
#pragma once
65

76
#include <ecoli.h>
87

98
int bash_complete(struct ec_node *cmdlist);
10-
11-
#endif

0 commit comments

Comments
 (0)