From 379056fb9cf3466da0297b05c8aea66f3096078c Mon Sep 17 00:00:00 2001 From: Michael Aldridge Date: Wed, 24 Jul 2019 10:48:03 -0700 Subject: [PATCH] Add compatibility for non GNU-libc --- compat/getgrent_r.c | 19 ++++++++++++++----- compat/getpwent_r.c | 9 ++++----- nss_cache.c | 11 ++++++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/compat/getgrent_r.c b/compat/getgrent_r.c index 1d20465..863413f 100644 --- a/compat/getgrent_r.c +++ b/compat/getgrent_r.c @@ -26,9 +26,9 @@ * Copyright © 2015 Kevin Bowling */ -#include - -#ifdef BSD +// This compat layer is only built for BSD, or Linux without the GNU C +// Library. +#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__)) #include #include @@ -37,6 +37,16 @@ #include #include +#if defined(BSD) +#include +#else +// This branch is necessarily Linux and not GNU because of the checks +// defined above that guard the rest of the compat layer. On Linux we +// don't pull in param.h as it is very obsolete. +#include +#define ALIGNBYTES _Alignof(max_align_t) +#define ALIGN(p)(((uintptr_t)(p) + ALIGNBYTES & ~ALIGNBYTES)) +#endif // defined(BSD) static unsigned atou(char **s) { unsigned x; @@ -104,5 +114,4 @@ int fgetgrent_r(FILE *f, struct group *gr, char *line, size_t size, struct group if(rv) errno = rv; return rv; } - -#endif // ifdef BSD +#endif //#if defined(BSD) || defined(__LINUX__) && !defined(__GLIBC__) diff --git a/compat/getpwent_r.c b/compat/getpwent_r.c index b1be6fc..de785a6 100644 --- a/compat/getpwent_r.c +++ b/compat/getpwent_r.c @@ -26,9 +26,9 @@ * Copyright © 2015 Kevin Bowling */ -#include - -#ifdef BSD +// This compat layer is only built for BSD, or Linux without the GNU C +// Library. +#if defined(BSD) || (defined(__linux__) && !defined(__GLIBC__)) #include #include @@ -83,5 +83,4 @@ int fgetpwent_r(FILE *f, struct passwd *pw, char *line, size_t size, struct pass if (rv) errno = rv; return rv; } - -#endif // ifdef BSD +#endif //#if defined(BSD) || defined(__LINUX__) && !defined(__GLIBC__) diff --git a/nss_cache.c b/nss_cache.c index 0cd113b..aabc0ef 100644 --- a/nss_cache.c +++ b/nss_cache.c @@ -730,7 +730,10 @@ enum nss_status _nss_cache_getgrnam_r(const char *name, struct group *result, // // Routines for shadow map defined here. // -#ifndef BSD +#if defined(__LINUX__) && defined(__GLIBC__) +// This is only built on GLIBC as caching the shadow file is generally +// not permissable from the perspective of other libc's, so the +// symbols are simply unused in those environments. // _nss_cache_setspent_path() // Helper function for testing @@ -915,6 +918,8 @@ enum nss_status _nss_cache_getspnam_r(const char *name, struct spwd *result, return ret; } -#else +#endif + +#ifdef BSD #include "bsdnss.c" -#endif // ifndef BSD +#endif // #if defined(__LINUX__) && defined(__GLIBC__)