typedef struct cipher cipher_t;
-extern cipher_t *cipher_alloc(void) __attribute__((__malloc__));
+extern cipher_t *cipher_alloc(void) ATTR_MALLOC;
extern void cipher_free(cipher_t **cipher);
extern bool cipher_open_by_name(cipher_t *cipher, const char *name);
extern bool cipher_open_by_nid(cipher_t *cipher, int nid);
extern size_t cipher_keylength(const cipher_t *cipher);
extern size_t cipher_blocksize(const cipher_t *cipher);
extern uint64_t cipher_budget(const cipher_t *cipher);
-extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) __attribute__((__warn_unused_result__));
-extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) __attribute__((__warn_unused_result__));
-extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__));
-extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__((__warn_unused_result__));
+extern bool cipher_set_key(cipher_t *cipher, void *key, bool encrypt) ATTR_WARN_UNUSED;
+extern bool cipher_set_key_from_rsa(cipher_t *cipher, void *rsa, size_t len, bool encrypt) ATTR_WARN_UNUSED;
+extern bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED;
+extern bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) ATTR_WARN_UNUSED;
extern int cipher_get_nid(const cipher_t *cipher);
extern bool cipher_active(const cipher_t *cipher);
extern splay_tree_t *create_configuration(void);
extern void init_configuration(splay_tree_t *);
extern void exit_configuration(splay_tree_t **config_tree);
-extern config_t *new_config(void) __attribute__((__malloc__));
+extern config_t *new_config(void) ATTR_MALLOC;
extern void free_config(config_t *config);
extern void config_add(splay_tree_t *config_tree, config_t *config);
extern config_t *lookup_config(splay_tree_t *config_tree, const char *variable);
extern void init_connections(void);
extern void exit_connections(void);
-extern connection_t *new_connection(void) __attribute__((__malloc__));
+extern connection_t *new_connection(void) ATTR_MALLOC;
extern void free_connection(connection_t *c);
extern void connection_add(connection_t *c);
extern void connection_del(connection_t *c);
extern bool digest_open_by_name(digest_t *digest, const char *name, size_t maclength);
extern bool digest_open_by_nid(digest_t *digest, int nid, size_t maclength);
-extern digest_t *digest_alloc(void) __attribute__((__malloc__));
+extern digest_t *digest_alloc(void) ATTR_MALLOC;
extern void digest_free(digest_t **digest);
extern void digest_close(digest_t *digest);
-extern bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *outdata) __attribute__((__warn_unused_result__));
-extern bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *digestdata) __attribute__((__warn_unused_result__));
-extern bool digest_set_key(digest_t *digest, const void *key, size_t len) __attribute__((__warn_unused_result__));
+extern bool digest_create(digest_t *digest, const void *indata, size_t inlen, void *outdata) ATTR_WARN_UNUSED;
+extern bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const void *digestdata) ATTR_WARN_UNUSED;
+extern bool digest_set_key(digest_t *digest, const void *key, size_t len) ATTR_WARN_UNUSED;
extern int digest_get_nid(const digest_t *digest);
extern size_t digest_keylength(const digest_t *digest);
extern size_t digest_length(const digest_t *digest);
#ifdef _MSC_VER
-#define __attribute(args)
-#define __attribute__(args)
-
#define PATH_MAX MAX_PATH
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
typedef struct ecdh ecdh_t;
#endif
-extern ecdh_t *ecdh_generate_public(void *pubkey) __attribute__((__malloc__));
-extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) __attribute__((__warn_unused_result__));
+extern ecdh_t *ecdh_generate_public(void *pubkey) ATTR_MALLOC;
+extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) ATTR_WARN_UNUSED;
extern void ecdh_free(ecdh_t *ecdh);
#endif
typedef struct ecdsa ecdsa_t;
#endif
-extern ecdsa_t *ecdsa_set_base64_public_key(const char *p) __attribute__((__malloc__));
+extern ecdsa_t *ecdsa_set_base64_public_key(const char *p) ATTR_MALLOC;
extern char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa);
-extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__));
-extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__));
+extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) ATTR_MALLOC;
+extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) ATTR_MALLOC;
extern size_t ecdsa_size(ecdsa_t *ecdsa);
-extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) __attribute__((__warn_unused_result__));
-extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) __attribute__((__warn_unused_result__));
+extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) ATTR_WARN_UNUSED;
+extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) ATTR_WARN_UNUSED;
extern bool ecdsa_active(ecdsa_t *ecdsa);
extern void ecdsa_free(ecdsa_t *ecdsa);
#include "ecdsa.h"
-extern ecdsa_t *ecdsa_generate(void) __attribute__((__malloc__));
-extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
-extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) __attribute__((__warn_unused_result__));
+extern ecdsa_t *ecdsa_generate(void) ATTR_MALLOC;
+extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) ATTR_WARN_UNUSED;
+extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) ATTR_WARN_UNUSED;
#endif
extern splay_tree_t edge_weight_tree; /* Tree with all known edges sorted on weight */
extern void exit_edges(void);
-extern edge_t *new_edge(void) __attribute__((__malloc__));
+extern edge_t *new_edge(void) ATTR_MALLOC;
extern void free_edge(edge_t *e);
extern void init_edge_tree(splay_tree_t *tree);
extern void edge_add(edge_t *e);
#endif
#endif
+#ifdef HAVE_ATTR_MALLOC
+#define ATTR_MALLOC __attribute__((__malloc__))
+#else
+#define ATTR_MALLOC
+#endif
+
+#ifdef HAVE_ATTR_NONNULL
+#define ATTR_NONNULL __attribute__((__nonnull__))
+#else
+#define ATTR_NONNULL
+#endif
+
+#ifdef HAVE_ATTR_WARN_UNUSED_RESULT
+#define ATTR_WARN_UNUSED __attribute__((__warn_unused_result__))
+#else
+#define ATTR_WARN_UNUSED
+#endif
+
+#ifdef HAVE_ATTR_FORMAT
+#define ATTR_FORMAT(func, str, nonstr) __attribute__((format(func, str, nonstr)))
+#else
+#define ATTR_FORMAT(func, str, nonstr)
+#endif
+
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#elif defined(HAVE_NETBSD)
/* (De)constructors */
-extern list_t *list_alloc(list_action_t delete) __attribute__((__malloc__));
+extern list_t *list_alloc(list_action_t delete) ATTR_MALLOC;
extern void list_free(list_t *list);
extern list_node_t *list_alloc_node(void);
extern void list_free_node(list_t *list, list_node_t *node);
extern int umbilical;
extern void openlogger(const char *ident, logmode_t mode);
extern void reopenlogger(void);
-extern void logger(debug_t level, int priority, const char *format, ...) __attribute__((__format__(printf, 3, 4)));
+extern void logger(debug_t level, int priority, const char *format, ...) ATTR_FORMAT(printf, 3, 4);
extern void closelogger(void);
#endif
cdata.set('HAVE_' + os_name.to_upper(), 1)
-foreach attr : ['malloc', 'nonnull', 'warn_unused_result', 'packed']
+foreach attr : ['malloc', 'nonnull', 'warn_unused_result', 'packed', 'format']
if cc.has_function_attribute(attr)
cdata.set('HAVE_ATTR_' + attr.to_upper(), 1,
- description: '__attribute__(@0@)'.format(attr))
+ description: '__attribute__((__@0@__))'.format(attr))
endif
endforeach
extern bool hostnames;
-extern struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) __attribute__((__malloc__));
+extern struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) ATTR_MALLOC;
extern sockaddr_t str2sockaddr(const char *address, const char *port);
extern void sockaddr2str(const sockaddr_t *sa, char **address, char **port);
-extern char *sockaddr2hostname(const sockaddr_t *sa) __attribute__((__malloc__));
+extern char *sockaddr2hostname(const sockaddr_t *sa) ATTR_MALLOC;
extern int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b);
extern int sockaddrcmp_noport(const sockaddr_t *a, const sockaddr_t *b);
extern void sockaddrunmap(sockaddr_t *sa);
extern splay_tree_t node_tree;
extern void exit_nodes(void);
-extern node_t *new_node(void) __attribute__((__malloc__));
+extern node_t *new_node(void) ATTR_MALLOC;
extern void free_node(node_t *n);
extern void node_add(node_t *n);
extern void node_del(node_t *n);
#include "system.h"
-extern bool prf(const uint8_t *secret, size_t secretlen, uint8_t *seed, size_t seedlen, uint8_t *out, size_t outlen) __attribute__((__warn_unused_result__));
+extern bool prf(const uint8_t *secret, size_t secretlen, uint8_t *seed, size_t seedlen, uint8_t *out, size_t outlen) ATTR_WARN_UNUSED;
#endif
/* Basic functions */
-extern bool send_request(struct connection_t *c, const char *format, ...) __attribute__((__format__(printf, 2, 3)));
+extern bool send_request(struct connection_t *c, const char *format, ...) ATTR_FORMAT(printf, 2, 3);
extern void forward_request(struct connection_t *c, const char *request);
extern bool receive_request(struct connection_t *c, const char *request);
#endif
extern void rsa_free(rsa_t *rsa);
-extern rsa_t *rsa_set_hex_public_key(const char *n, const char *e) __attribute__((__malloc__));
-extern rsa_t *rsa_set_hex_private_key(const char *n, const char *e, const char *d) __attribute__((__malloc__));
-extern rsa_t *rsa_read_pem_public_key(FILE *fp) __attribute__((__malloc__));
-extern rsa_t *rsa_read_pem_private_key(FILE *fp) __attribute__((__malloc__));
+extern rsa_t *rsa_set_hex_public_key(const char *n, const char *e) ATTR_MALLOC;
+extern rsa_t *rsa_set_hex_private_key(const char *n, const char *e, const char *d) ATTR_MALLOC;
+extern rsa_t *rsa_read_pem_public_key(FILE *fp) ATTR_MALLOC;
+extern rsa_t *rsa_read_pem_private_key(FILE *fp) ATTR_MALLOC;
extern size_t rsa_size(const rsa_t *rsa);
-extern bool rsa_public_encrypt(rsa_t *rsa, const void *in, size_t len, void *out) __attribute__((__warn_unused_result__));
-extern bool rsa_private_decrypt(rsa_t *rsa, const void *in, size_t len, void *out) __attribute__((__warn_unused_result__));
+extern bool rsa_public_encrypt(rsa_t *rsa, const void *in, size_t len, void *out) ATTR_WARN_UNUSED;
+extern bool rsa_private_decrypt(rsa_t *rsa, const void *in, size_t len, void *out) ATTR_WARN_UNUSED;
#endif
#include "rsa.h"
-extern rsa_t *rsa_generate(size_t bits, unsigned long exponent) __attribute__((__malloc__));
-extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) __attribute__((__warn_unused_result__));
-extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) __attribute__((__warn_unused_result__));
+extern rsa_t *rsa_generate(size_t bits, unsigned long exponent) ATTR_MALLOC;
+extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) ATTR_WARN_UNUSED;
+extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) ATTR_WARN_UNUSED;
#endif
/* (De)constructors */
-extern splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) __attribute__((__malloc__));
+extern splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) ATTR_MALLOC;
extern void splay_free_tree(splay_tree_t *tree);
-extern splay_node_t *splay_alloc_node(void) __attribute__((__malloc__));
+extern splay_node_t *splay_alloc_node(void) ATTR_MALLOC;
extern void splay_free_node(splay_tree_t *tree, splay_node_t *node);
/* Insertion and deletion */
extern splay_tree_t subnet_tree;
extern int subnet_compare(const struct subnet_t *a, const struct subnet_t *b);
-extern subnet_t *new_subnet(void) __attribute__((__malloc__));
+extern subnet_t *new_subnet(void) ATTR_MALLOC;
extern void free_subnet(subnet_t *subnet);
extern void init_subnets(void);
extern void exit_subnets(void);
#include "system.h"
-static inline void *xmalloc(size_t n) __attribute__((__malloc__));
+static inline void *xmalloc(size_t n) ATTR_MALLOC;
static inline void *xmalloc(size_t n) {
void *p = malloc(n);
return p;
}
-static inline void *xzalloc(size_t n) __attribute__((__malloc__));
+static inline void *xzalloc(size_t n) ATTR_MALLOC;
static inline void *xzalloc(size_t n) {
void *p = calloc(1, n);
return p;
}
-static inline char *xstrdup(const char *s) __attribute__((__malloc__)) __attribute((__nonnull__));
+static inline char *xstrdup(const char *s) ATTR_MALLOC ATTR_NONNULL;
static inline char *xstrdup(const char *s) {
char *p = strdup(s);
return result;
}
-static inline int xasprintf(char **strp, const char *fmt, ...) __attribute__((__format__(printf, 2, 3)));
+static inline int xasprintf(char **strp, const char *fmt, ...) ATTR_FORMAT(printf, 2, 3);
static inline int xasprintf(char **strp, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);