diff options
author | Rohan Joyce <rojoyce.github@gmail.com> | 2015-02-13 10:26:01 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-02-16 10:20:18 (GMT) |
commit | 6f891f6c0c9ca68658491fe3b959613809309027 (patch) | |
tree | b0a8b5a03fba2b80729a06d1dde413084cac5e7b /include | |
parent | e75a1c373ad447ddf376b77f36c8e4ef039de3b5 (diff) | |
download | libnl-6f891f6c0c9ca68658491fe3b959613809309027.zip libnl-6f891f6c0c9ca68658491fe3b959613809309027.tar.gz libnl-6f891f6c0c9ca68658491fe3b959613809309027.tar.bz2 |
lib: add const-ness to appropriate parameters in addr, attr, data
This patch changes the signatures of some functions to allow const pointers in
places where a const qualified pointer is enough access for what the function
does (e.g. nla_get_u8). It also changes some functions that take a pointer
parameter and return a pointer derived from it to use the strchr idiom.
This is not exhaustive in terms of places where const can be added, but it's
a decent chunk that should not make the external api any more restrictive.
http://lists.infradead.org/pipermail/libnl/2015-February/001826.html
Signed-off-by: Rohan Joyce <rojoyce.github@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/netlink/addr.h | 39 | ||||
-rw-r--r-- | include/netlink/attr.h | 34 | ||||
-rw-r--r-- | include/netlink/data.h | 15 |
3 files changed, 47 insertions, 41 deletions
diff --git a/include/netlink/addr.h b/include/netlink/addr.h index db3e4c2..9d0d24a 100644 --- a/include/netlink/addr.h +++ b/include/netlink/addr.h @@ -22,42 +22,45 @@ struct nl_addr; /* Creation */ extern struct nl_addr * nl_addr_alloc(size_t); -extern struct nl_addr * nl_addr_alloc_attr(struct nlattr *, int); -extern struct nl_addr * nl_addr_build(int, void *, size_t); +extern struct nl_addr * nl_addr_alloc_attr(const struct nlattr *, int); +extern struct nl_addr * nl_addr_build(int, const void *, size_t); extern int nl_addr_parse(const char *, int, struct nl_addr **); -extern struct nl_addr * nl_addr_clone(struct nl_addr *); +extern struct nl_addr * nl_addr_clone(const struct nl_addr *); /* Usage Management */ extern struct nl_addr * nl_addr_get(struct nl_addr *); extern void nl_addr_put(struct nl_addr *); -extern int nl_addr_shared(struct nl_addr *); +extern int nl_addr_shared(const struct nl_addr *); -extern int nl_addr_cmp(struct nl_addr *, struct nl_addr *); -extern int nl_addr_cmp_prefix(struct nl_addr *, struct nl_addr *); -extern int nl_addr_iszero(struct nl_addr *); -extern int nl_addr_valid(char *, int); -extern int nl_addr_guess_family(struct nl_addr *); -extern int nl_addr_fill_sockaddr(struct nl_addr *, +extern int nl_addr_cmp(const struct nl_addr *, + const struct nl_addr *); +extern int nl_addr_cmp_prefix(const struct nl_addr *, + const struct nl_addr *); +extern int nl_addr_iszero(const struct nl_addr *); +extern int nl_addr_valid(const char *, int); +extern int nl_addr_guess_family(const struct nl_addr *); +extern int nl_addr_fill_sockaddr(const struct nl_addr *, struct sockaddr *, socklen_t *); -extern int nl_addr_info(struct nl_addr *, struct addrinfo **); -extern int nl_addr_resolve(struct nl_addr *, char *, size_t); +extern int nl_addr_info(const struct nl_addr *, + struct addrinfo **); +extern int nl_addr_resolve(const struct nl_addr *, char *, size_t); /* Access Functions */ extern void nl_addr_set_family(struct nl_addr *, int); -extern int nl_addr_get_family(struct nl_addr *); -extern int nl_addr_set_binary_addr(struct nl_addr *, void *, +extern int nl_addr_get_family(const struct nl_addr *); +extern int nl_addr_set_binary_addr(struct nl_addr *, const void *, size_t); -extern void * nl_addr_get_binary_addr(struct nl_addr *); -extern unsigned int nl_addr_get_len(struct nl_addr *); +extern void * nl_addr_get_binary_addr(const struct nl_addr *); +extern unsigned int nl_addr_get_len(const struct nl_addr *); extern void nl_addr_set_prefixlen(struct nl_addr *, int); -extern unsigned int nl_addr_get_prefixlen(struct nl_addr *); +extern unsigned int nl_addr_get_prefixlen(const struct nl_addr *); /* Address Family Translations */ extern char * nl_af2str(int, char *, size_t); extern int nl_str2af(const char *); /* Translations to Strings */ -extern char * nl_addr2str(struct nl_addr *, char *, size_t); +extern char * nl_addr2str(const struct nl_addr *, char *, size_t); #ifdef __cplusplus } diff --git a/include/netlink/attr.h b/include/netlink/attr.h index 82e4c38..b84b62e 100644 --- a/include/netlink/attr.h +++ b/include/netlink/attr.h @@ -81,12 +81,12 @@ extern int nla_ok(const struct nlattr *, int); extern struct nlattr * nla_next(const struct nlattr *, int *); extern int nla_parse(struct nlattr **, int, struct nlattr *, int, struct nla_policy *); -extern int nla_validate(struct nlattr *, int, int, - struct nla_policy *); -extern struct nlattr * nla_find(struct nlattr *, int, int); +extern int nla_validate(const struct nlattr *, int, int, + const struct nla_policy *); +extern struct nlattr * nla_find(const struct nlattr *, int, int); /* Helper Functions */ -extern int nla_memcpy(void *, struct nlattr *, int); +extern int nla_memcpy(void *, const struct nlattr *, int); extern size_t nla_strlcpy(char *, const struct nlattr *, size_t); extern int nla_memcmp(const struct nlattr *, const void *, size_t); extern int nla_strcmp(const struct nlattr *, const char *); @@ -94,40 +94,42 @@ extern int nla_strcmp(const struct nlattr *, const char *); /* Unspecific attribute */ extern struct nlattr * nla_reserve(struct nl_msg *, int, int); extern int nla_put(struct nl_msg *, int, int, const void *); -extern int nla_put_data(struct nl_msg *, int, struct nl_data *); +extern int nla_put_data(struct nl_msg *, int, + const struct nl_data *); extern int nla_put_addr(struct nl_msg *, int, struct nl_addr *); /* Integer attribute */ -extern uint8_t nla_get_u8(struct nlattr *); +extern uint8_t nla_get_u8(const struct nlattr *); extern int nla_put_u8(struct nl_msg *, int, uint8_t); -extern uint16_t nla_get_u16(struct nlattr *); +extern uint16_t nla_get_u16(const struct nlattr *); extern int nla_put_u16(struct nl_msg *, int, uint16_t); -extern uint32_t nla_get_u32(struct nlattr *); +extern uint32_t nla_get_u32(const struct nlattr *); extern int nla_put_u32(struct nl_msg *, int, uint32_t); -extern uint64_t nla_get_u64(struct nlattr *); +extern uint64_t nla_get_u64(const struct nlattr *); extern int nla_put_u64(struct nl_msg *, int, uint64_t); /* String attribute */ -extern char * nla_get_string(struct nlattr *); -extern char * nla_strdup(struct nlattr *); +extern char * nla_get_string(const struct nlattr *); +extern char * nla_strdup(const struct nlattr *); extern int nla_put_string(struct nl_msg *, int, const char *); /* Flag attribute */ -extern int nla_get_flag(struct nlattr *); +extern int nla_get_flag(const struct nlattr *); extern int nla_put_flag(struct nl_msg *, int); /* Msec attribute */ -extern unsigned long nla_get_msecs(struct nlattr *); +extern unsigned long nla_get_msecs(const struct nlattr *); extern int nla_put_msecs(struct nl_msg *, int, unsigned long); /* Attribute nesting */ -extern int nla_put_nested(struct nl_msg *, int, struct nl_msg *); +extern int nla_put_nested(struct nl_msg *, int, + const struct nl_msg *); extern struct nlattr * nla_nest_start(struct nl_msg *, int); extern int nla_nest_end(struct nl_msg *, struct nlattr *); -extern void nla_nest_cancel(struct nl_msg *, struct nlattr *); +extern void nla_nest_cancel(struct nl_msg *, const struct nlattr *); extern int nla_parse_nested(struct nlattr **, int, struct nlattr *, struct nla_policy *); -extern int nla_is_nested(struct nlattr *); +extern int nla_is_nested(const struct nlattr *); /** * @name Attribute Construction (Exception Based) diff --git a/include/netlink/data.h b/include/netlink/data.h index 071159e..b091c4b 100644 --- a/include/netlink/data.h +++ b/include/netlink/data.h @@ -21,18 +21,19 @@ extern "C" { struct nl_data; /* General */ -extern struct nl_data * nl_data_alloc(void *, size_t); -extern struct nl_data * nl_data_alloc_attr(struct nlattr *); -extern struct nl_data * nl_data_clone(struct nl_data *); -extern int nl_data_append(struct nl_data *, void *, size_t); +extern struct nl_data * nl_data_alloc(const void *, size_t); +extern struct nl_data * nl_data_alloc_attr(const struct nlattr *); +extern struct nl_data * nl_data_clone(const struct nl_data *); +extern int nl_data_append(struct nl_data *, const void *, size_t); extern void nl_data_free(struct nl_data *); /* Access Functions */ -extern void * nl_data_get(struct nl_data *); -extern size_t nl_data_get_size(struct nl_data *); +extern void * nl_data_get(const struct nl_data *); +extern size_t nl_data_get_size(const struct nl_data *); /* Misc */ -extern int nl_data_cmp(struct nl_data *, struct nl_data *); +extern int nl_data_cmp(const struct nl_data *, + const struct nl_data *); #ifdef __cplusplus } |