>From c5e93bb2dc53e2ae05b302904759f91649bbb23d Mon Sep 17 00:00:00 2001 From: Yury Usishchev Date: Thu, 11 Feb 2016 17:26:25 +0300 Subject: [PATCH] Cleanup visibility of API functions Add visibility attribute to public headers and -fvisibility=hidden compiler option when visibility is supported by compiler. --- include/Makemodule.am | 24 +++++++++++++++------ include/acl.h | 56 ++++++++++++++++++++++++------------------------- include/libacl.h | 26 +++++++++++------------ m4/visibility_hidden.m4 | 4 ++++ 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/include/Makemodule.am b/include/Makemodule.am index 37364d3..e4c5df8 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -1,10 +1,22 @@ -pkginclude_HEADERS += \ - include/libacl.h - -sysinclude_HEADERS += \ - include/acl.h - noinst_HEADERS += \ + include/libacl.h \ + include/acl.h \ include/acl_ea.h \ include/misc.h \ include/walk_tree.h + +SUBST_INSTALL_HEADER = \ + subst_install_header() { \ + file=`echo "$$1" | sed -e 's,^.*/,,'`; \ + $(SED) -e "s/\/extern/" < "$$1" > "include/$$file.t" || exit 1; \ + $(MKDIR_P) "$$2" || exit 1; \ + $(INSTALL_HEADER) "include/$$file.t" "$$2/$$file" || exit 1; \ + $(RM) "include/$$file.t"; \ + }; \ + subst_install_header + +install-libacl_h: include/libacl.h + $(SUBST_INSTALL_HEADER) "$<" "$(DESTDIR)$(pkgincludedir)" +install-acl_h: include/acl.h + $(SUBST_INSTALL_HEADER) "$<" "$(DESTDIR)$(sysincludedir)" +install-data-local: install-libacl_h install-acl_h diff --git a/include/acl.h b/include/acl.h index e3347e1..7e1b0b8 100644 --- a/include/acl.h +++ b/include/acl.h @@ -77,50 +77,50 @@ typedef struct __acl_permset_ext *acl_permset_t; /*=== ACL manipulation ===*/ -extern acl_t acl_init(int count); -extern acl_t acl_dup(acl_t acl); -extern int acl_free(void *obj_p); -extern int acl_valid(acl_t acl); +EXPORT acl_t acl_init(int count); +EXPORT acl_t acl_dup(acl_t acl); +EXPORT int acl_free(void *obj_p); +EXPORT int acl_valid(acl_t acl); /*=== Entry manipulation ===*/ -extern int +EXPORT int acl_copy_entry(acl_entry_t dest_d, acl_entry_t src_d); -extern int acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p); -extern int acl_delete_entry(acl_t acl, acl_entry_t entry_d); -extern int acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p); +EXPORT int acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p); +EXPORT int acl_delete_entry(acl_t acl, acl_entry_t entry_d); +EXPORT int acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p); /* Manipulate ACL entry permissions */ -extern int acl_add_perm(acl_permset_t permset_d, acl_perm_t perm); -extern int acl_calc_mask(acl_t *acl_p); -extern int acl_clear_perms(acl_permset_t permset_d); -extern int acl_delete_perm(acl_permset_t permset_d, acl_perm_t perm); -extern int acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p); -extern int acl_set_permset(acl_entry_t entry_d, acl_permset_t permset_d); +EXPORT int acl_add_perm(acl_permset_t permset_d, acl_perm_t perm); +EXPORT int acl_calc_mask(acl_t *acl_p); +EXPORT int acl_clear_perms(acl_permset_t permset_d); +EXPORT int acl_delete_perm(acl_permset_t permset_d, acl_perm_t perm); +EXPORT int acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p); +EXPORT int acl_set_permset(acl_entry_t entry_d, acl_permset_t permset_d); /* Manipulate ACL entry tag type and qualifier */ -extern void * acl_get_qualifier(acl_entry_t entry_d); -extern int acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p); -extern int acl_set_qualifier(acl_entry_t entry_d, const void *tag_qualifier_p); -extern int acl_set_tag_type(acl_entry_t entry_d, acl_tag_t tag_type); +EXPORT void * acl_get_qualifier(acl_entry_t entry_d); +EXPORT int acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p); +EXPORT int acl_set_qualifier(acl_entry_t entry_d, const void *tag_qualifier_p); +EXPORT int acl_set_tag_type(acl_entry_t entry_d, acl_tag_t tag_type); /*=== Format translation ===*/ -extern ssize_t acl_copy_ext(void *buf_p, acl_t acl, ssize_t size); -extern acl_t acl_copy_int(const void *buf_p); -extern acl_t acl_from_text(const char *buf_p); -extern ssize_t acl_size(acl_t acl); -extern char *acl_to_text(acl_t acl, ssize_t *len_p); +EXPORT ssize_t acl_copy_ext(void *buf_p, acl_t acl, ssize_t size); +EXPORT acl_t acl_copy_int(const void *buf_p); +EXPORT acl_t acl_from_text(const char *buf_p); +EXPORT ssize_t acl_size(acl_t acl); +EXPORT char *acl_to_text(acl_t acl, ssize_t *len_p); /*=== Object manipulation ===*/ -extern int acl_delete_def_file(const char *path_p); -extern acl_t acl_get_fd(int fd); -extern acl_t acl_get_file(const char *path_p, acl_type_t type); -extern int acl_set_fd(int fd, acl_t acl); -extern int acl_set_file(const char *path_p, acl_type_t type, acl_t acl); +EXPORT int acl_delete_def_file(const char *path_p); +EXPORT acl_t acl_get_fd(int fd); +EXPORT acl_t acl_get_file(const char *path_p, acl_type_t type); +EXPORT int acl_set_fd(int fd, acl_t acl); +EXPORT int acl_set_file(const char *path_p, acl_type_t type, acl_t acl); #ifdef __cplusplus } diff --git a/include/libacl.h b/include/libacl.h index d6a6650..63ddcf6 100644 --- a/include/libacl.h +++ b/include/libacl.h @@ -52,24 +52,24 @@ extern "C" { #define ACL_MISS_ERROR (0x3000) /* missing required entry */ #define ACL_ENTRY_ERROR (0x4000) /* wrong entry type */ -extern char *acl_to_any_text(acl_t acl, const char *prefix, +EXPORT char *acl_to_any_text(acl_t acl, const char *prefix, char separator, int options); -extern int acl_cmp(acl_t acl1, acl_t acl2); -extern int acl_check(acl_t acl, int *last); -extern acl_t acl_from_mode(mode_t mode); -extern int acl_equiv_mode(acl_t acl, mode_t *mode_p); -int acl_extended_file(const char *path_p); -int acl_extended_file_nofollow(const char *path_p); -int acl_extended_fd(int fd); -extern int acl_entries(acl_t acl); -extern const char *acl_error(int code); -extern int acl_get_perm(acl_permset_t permset_d, acl_perm_t perm); +EXPORT int acl_cmp(acl_t acl1, acl_t acl2); +EXPORT int acl_check(acl_t acl, int *last); +EXPORT acl_t acl_from_mode(mode_t mode); +EXPORT int acl_equiv_mode(acl_t acl, mode_t *mode_p); +EXPORT int acl_extended_file(const char *path_p); +EXPORT int acl_extended_file_nofollow(const char *path_p); +EXPORT int acl_extended_fd(int fd); +EXPORT int acl_entries(acl_t acl); +EXPORT const char *acl_error(int code); +EXPORT int acl_get_perm(acl_permset_t permset_d, acl_perm_t perm); /* Copying permissions between files */ struct error_context; -extern int perm_copy_file (const char *, const char *, +EXPORT int perm_copy_file (const char *, const char *, struct error_context *); -extern int perm_copy_fd (const char *, int, const char *, int, +EXPORT int perm_copy_fd (const char *, int, const char *, int, struct error_context *); #ifdef __cplusplus diff --git a/m4/visibility_hidden.m4 b/m4/visibility_hidden.m4 index 808a8e3..dbd57d4 100644 --- a/m4/visibility_hidden.m4 +++ b/m4/visibility_hidden.m4 @@ -32,5 +32,9 @@ EOF ]) if test $libc_cv_visibility_attribute = yes; then AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE, [], [GCC supports visibility attributes]) + AC_DEFINE(EXPORT, [__attribute__ ((visibility ("default"))) extern], [Visibility attribute for API symbols]) + CFLAGS="${CFLAGS} -fvisibility=hidden" + else + AC_DEFINE(EXPORT, [extern], [Visibility attribute for API symbols]) fi ]) -- 2.7.2