From 22f4c7005e9ca07a493f84eac2f529ec369649f3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 14 Aug 2020 16:27:35 -0400 Subject: add __pwd.c for internal state --- src/pwd/__pwd.c | 18 ++++++++++++++++++ src/pwd/_pwd.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/pwd/__pwd.c create mode 100644 src/pwd/_pwd.h (limited to 'src/pwd') diff --git a/src/pwd/__pwd.c b/src/pwd/__pwd.c new file mode 100644 index 00000000..c6fb7787 --- /dev/null +++ b/src/pwd/__pwd.c @@ -0,0 +1,18 @@ +#include "_pwd.h" + +#ifndef _XOPEN_SOURCE +#undef getpwent +#define getpwent __getpwent +#include "getpwent.c" +#endif + +struct __pwd __pwd = +{ + NULL, + { 0 }, + getpwent, +}; + +/* +POSIX(1) +*/ diff --git a/src/pwd/_pwd.h b/src/pwd/_pwd.h new file mode 100644 index 00000000..b5d666bf --- /dev/null +++ b/src/pwd/_pwd.h @@ -0,0 +1,29 @@ +#ifndef ___PWD_H__ +#define ___PWD_H__ + +#include +#include +#include + +struct __pwd { + FILE *db; + struct passwd pwd; + struct passwd * (*getpwent)(void); +}; + +extern struct __pwd __pwd; + +#ifndef _XOPEN_SOURCE +#define setpwent() (__pwd.db == NULL ? (void)0 : (void)rewind(__pwd.db)) + +#define endpwent() do { \ + if (__pwd.db) { \ + fclose(__pwd.db); \ + __pwd.db = NULL; \ + } \ +} while (0) + +#define getpwent __pwd.getpwent +#endif + +#endif -- cgit v1.2.1