[PATCH v2 08/10] nss: Use macro to generate public API names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The name of the exported functions for an NSS module is quite
fixed, it is derived from the module name:

  _nss_$module_$function

Since we will create another NSS module with very similar
implementation we might as well generate the function names at
the compile time.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/nsslinktest.c     |  2 +-
 tests/nsstest.c         | 12 ++++++------
 tools/nss/libvirt_nss.c | 41 ++++++++++++++++++++---------------------
 tools/nss/libvirt_nss.h | 26 ++++++++++++++------------
 4 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/tests/nsslinktest.c b/tests/nsslinktest.c
index 0232e362a..a81a6d331 100644
--- a/tests/nsslinktest.c
+++ b/tests/nsslinktest.c
@@ -33,7 +33,7 @@ int main(int argc ATTRIBUTE_UNUSED,
      * the fact this test has been built successfully means
      * there's no linkage problem and therefore success is
      * returned. */
-    _nss_libvirt_gethostbyname_r(NULL, NULL, NULL, 0, &err, &herrno);
+    NSS_NAME(gethostbyname)(NULL, NULL, NULL, 0, &err, &herrno);
 
     return EXIT_SUCCESS;
 }
diff --git a/tests/nsstest.c b/tests/nsstest.c
index 8648c4afb..c7fb11fd5 100644
--- a/tests/nsstest.c
+++ b/tests/nsstest.c
@@ -53,12 +53,12 @@ testGetHostByName(const void *opaque)
 
     memset(&resolved, 0, sizeof(resolved));
 
-    rv = _nss_libvirt_gethostbyname2_r(data->hostname,
-                                       data->af,
-                                       &resolved,
-                                       buf, sizeof(buf),
-                                       &tmp_errno,
-                                       &tmp_herrno);
+    rv = NSS_NAME(gethostbyname2)(data->hostname,
+                                  data->af,
+                                  &resolved,
+                                  buf, sizeof(buf),
+                                  &tmp_errno,
+                                  &tmp_herrno);
 
     if (rv == NSS_STATUS_TRYAGAIN ||
         rv == NSS_STATUS_UNAVAIL ||
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index 0d5982529..d77c9ece5 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -253,23 +253,23 @@ findLease(const char *name,
 
 
 enum nss_status
-_nss_libvirt_gethostbyname_r(const char *name, struct hostent *result,
-                             char *buffer, size_t buflen, int *errnop,
-                             int *herrnop)
+NSS_NAME(gethostbyname)(const char *name, struct hostent *result,
+                        char *buffer, size_t buflen, int *errnop,
+                        int *herrnop)
 {
     int af = ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET);
 
-    return _nss_libvirt_gethostbyname3_r(name, af, result, buffer, buflen,
-                                         errnop, herrnop, NULL, NULL);
+    return NSS_NAME(gethostbyname3)(name, af, result, buffer, buflen,
+                                    errnop, herrnop, NULL, NULL);
 }
 
 enum nss_status
-_nss_libvirt_gethostbyname2_r(const char *name, int af, struct hostent *result,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop)
+NSS_NAME(gethostbyname2)(const char *name, int af, struct hostent *result,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop)
 {
-    return _nss_libvirt_gethostbyname3_r(name, af, result, buffer, buflen,
-                                         errnop, herrnop, NULL, NULL);
+    return NSS_NAME(gethostbyname3)(name, af, result, buffer, buflen,
+                                    errnop, herrnop, NULL, NULL);
 }
 
 static inline void *
@@ -287,9 +287,9 @@ move_and_align(void *buf, size_t len, size_t *idx)
 }
 
 enum nss_status
-_nss_libvirt_gethostbyname3_r(const char *name, int af, struct hostent *result,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop, int32_t *ttlp, char **canonp)
+NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop, int32_t *ttlp, char **canonp)
 {
     enum nss_status ret = NSS_STATUS_UNAVAIL;
     char *r_name, **r_aliases, *r_addr, *r_addr_next, **r_addr_list;
@@ -405,9 +405,9 @@ _nss_libvirt_gethostbyname3_r(const char *name, int af, struct hostent *result,
 
 #ifdef HAVE_STRUCT_GAIH_ADDRTUPLE
 enum nss_status
-_nss_libvirt_gethostbyname4_r(const char *name, struct gaih_addrtuple **pat,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop, int32_t *ttlp)
+NSS_NAME(gethostbyname4)(const char *name, struct gaih_addrtuple **pat,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop, int32_t *ttlp)
 {
     enum nss_status ret = NSS_STATUS_UNAVAIL;
     leaseAddress *addr = NULL;
@@ -517,9 +517,9 @@ aiforaf(const char *name, int af, struct addrinfo *pai, struct addrinfo **aip)
     struct addrinfo hints, *res0, *res;
     char **addrList;
 
-    if ((ret = _nss_libvirt_gethostbyname2_r(name, af, &resolved,
-                                             buf, sizeof(buf),
-                                             &err, &herr)) != NS_SUCCESS)
+    if ((ret = NSS_NAME(gethostbyname2)(name, af, &resolved,
+                                        buf, sizeof(buf),
+                                        &err, &herr)) != NS_SUCCESS)
         return;
 
     addrList = resolved.h_addr_list;
@@ -604,8 +604,7 @@ _nss_compat_gethostbyname2_r(void *retval, void *mdata ATTRIBUTE_UNUSED, va_list
     errnop = va_arg(ap, int *);
     herrnop = va_arg(ap, int *);
 
-    ret = _nss_libvirt_gethostbyname2_r(
-              name, af, result, buffer, buflen, errnop, herrnop);
+    ret = NSS_NAME(gethostbyname2)(name, af, result, buffer, buflen, errnop, herrnop);
     *(struct hostent **)retval = (ret == NS_SUCCESS) ? result : NULL;
 
     return ret;
diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h
index e025e6362..481d8828b 100644
--- a/tools/nss/libvirt_nss.h
+++ b/tools/nss/libvirt_nss.h
@@ -32,24 +32,26 @@
 # include <nss.h>
 # include <netdb.h>
 
+# define NSS_NAME(s) _nss_libvirt_##s##_r
+
 enum nss_status
-_nss_libvirt_gethostbyname_r(const char *name, struct hostent *result,
-                             char *buffer, size_t buflen, int *errnop,
-                             int *herrnop);
+NSS_NAME(gethostbyname)(const char *name, struct hostent *result,
+                        char *buffer, size_t buflen, int *errnop,
+                        int *herrnop);
 
 enum nss_status
-_nss_libvirt_gethostbyname2_r(const char *name, int af, struct hostent *result,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop);
+NSS_NAME(gethostbyname2)(const char *name, int af, struct hostent *result,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop);
 enum nss_status
-_nss_libvirt_gethostbyname3_r(const char *name, int af, struct hostent *result,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop, int32_t *ttlp, char **canonp);
+NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop, int32_t *ttlp, char **canonp);
 # ifdef HAVE_STRUCT_GAIH_ADDRTUPLE
 enum nss_status
-_nss_libvirt_gethostbyname4_r(const char *name, struct gaih_addrtuple **pat,
-                              char *buffer, size_t buflen, int *errnop,
-                              int *herrnop, int32_t *ttlp);
+NSS_NAME(gethostbyname4)(const char *name, struct gaih_addrtuple **pat,
+                         char *buffer, size_t buflen, int *errnop,
+                         int *herrnop, int32_t *ttlp);
 # endif /* HAVE_STRUCT_GAIH_ADDRTUPLE */
 
 # if defined(HAVE_BSD_NSS)
-- 
2.11.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux