Skip to content

Commit 4199f68

Browse files
committed
Use c99 static array size declarations in exported functions too
It seems quite useful to provide this additional information in public exported functions. This is a c99 feature, not supported in C++. Without the check in _sd-common.h: FAILED: test-bus-vtable-cc@exe/src_libsystemd_sd-bus_test-bus-vtable-cc.cc.o ... In file included from ../src/libsystemd/sd-bus/test-bus-vtable-cc.cc:9: In file included from ../src/systemd/sd-bus-vtable.h:26: In file included from ../src/systemd/sd-bus.h:26: ../src/systemd/sd-id128.h:38:47: error: static array size is a C99 feature, not permitted in C++ char *sd_id128_to_string(sd_id128_t id, char s[static SD_ID128_STRING_MAX]); ^ In .c files, I opted to use the define for consistency, even though we don't support compilation with a C++ compiler, so the unconditional keyword would work too.
1 parent 3042bbe commit 4199f68

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/libsystemd-network/lldp-neighbor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ _public_ int sd_lldp_neighbor_tlv_is_type(sd_lldp_neighbor *n, uint8_t type) {
691691
return type == k;
692692
}
693693

694-
_public_ int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[3], uint8_t *subtype) {
694+
_public_ int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t *subtype) {
695695
const uint8_t *d;
696696
size_t length;
697697
int r;
@@ -720,7 +720,7 @@ _public_ int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[3], u
720720
return 0;
721721
}
722722

723-
_public_ int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[3], uint8_t subtype) {
723+
_public_ int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t subtype) {
724724
uint8_t k[3], st;
725725
int r;
726726

src/libsystemd/sd-id128/sd-id128.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "user-util.h"
1919
#include "util.h"
2020

21-
_public_ char *sd_id128_to_string(sd_id128_t id, char s[SD_ID128_STRING_MAX]) {
21+
_public_ char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]) {
2222
unsigned n;
2323

2424
assert_return(s, NULL);

src/systemd/_sd-common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ typedef void (*_sd_destroy_t)(void *userdata);
7272
# endif
7373
#endif
7474

75+
#ifndef _SD_ARRAY_STATIC
76+
# if __STDC_VERSION__ >= 199901L
77+
# define _SD_ARRAY_STATIC static
78+
# else
79+
# define _SD_ARRAY_STATIC
80+
# endif
81+
#endif
82+
7583
#define _SD_DEFINE_POINTER_CLEANUP_FUNC(type, func) \
7684
static __inline__ void func##p(type **p) { \
7785
if (*p) \

src/systemd/sd-id128.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ union sd_id128 {
3535

3636
#define SD_ID128_STRING_MAX 33
3737

38-
char *sd_id128_to_string(sd_id128_t id, char s[SD_ID128_STRING_MAX]);
38+
char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]);
3939
int sd_id128_from_string(const char *s, sd_id128_t *ret);
4040

4141
int sd_id128_randomize(sd_id128_t *ret);

src/systemd/sd-lldp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ int sd_lldp_neighbor_tlv_rewind(sd_lldp_neighbor *n);
168168
int sd_lldp_neighbor_tlv_next(sd_lldp_neighbor *n);
169169
int sd_lldp_neighbor_tlv_get_type(sd_lldp_neighbor *n, uint8_t *type);
170170
int sd_lldp_neighbor_tlv_is_type(sd_lldp_neighbor *n, uint8_t type);
171-
int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[3], uint8_t *subtype);
172-
int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[3], uint8_t subtype);
171+
int sd_lldp_neighbor_tlv_get_oui(sd_lldp_neighbor *n, uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t *subtype);
172+
int sd_lldp_neighbor_tlv_is_oui(sd_lldp_neighbor *n, const uint8_t oui[_SD_ARRAY_STATIC 3], uint8_t subtype);
173173
int sd_lldp_neighbor_tlv_get_raw(sd_lldp_neighbor *n, const void **ret, size_t *size);
174174

175175
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_lldp, sd_lldp_unref);

0 commit comments

Comments
 (0)