summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src/getgrent.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-14 11:01:48 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-20 10:30:21 +0100
commitb471854bc2168792fb628563588d2e85a73b2a4f (patch)
tree5489aca502e42533e5b9b5cabe31e51ca40865d8 /cpukit/libcsupport/src/getgrent.c
parentlibcsupport: Add copyrights according to rev hist (diff)
downloadrtems-b471854bc2168792fb628563588d2e85a73b2a4f.tar.bz2
libcsupport: Split passwd/group support
Diffstat (limited to 'cpukit/libcsupport/src/getgrent.c')
-rw-r--r--cpukit/libcsupport/src/getgrent.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/cpukit/libcsupport/src/getgrent.c b/cpukit/libcsupport/src/getgrent.c
new file mode 100644
index 0000000000..9b11e2ee08
--- /dev/null
+++ b/cpukit/libcsupport/src/getgrent.c
@@ -0,0 +1,78 @@
+/**
+ * @file
+ *
+ * @brief User Database Access Routines
+ * @ingroup libcsupport
+ */
+
+/*
+ * Copyright (c) 1999-2009 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
+ * Copyright (c) 1999-2013 Joel Sherrill <joel.sherrill@OARcorp.com>
+ * Copyright (c) 2000-2001 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
+ * Copyright (c) 2002 Eric Norum <eric.norum@usask.ca>
+ * Copyright (c) 2003 Till Straumann <strauman@slac.stanford.edu>
+ * Copyright (c) 2012 Alex Ivanov <alexivanov97@gmail.com>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pwdgrp.h"
+
+/*
+ * Static, thread-unsafe, buffers
+ */
+static FILE *group_fp;
+static char grbuf[200];
+static struct group grent;
+
+struct group *getgrnam(
+ const char *name
+)
+{
+ struct group *p;
+
+ if(getgrnam_r(name, &grent, grbuf, sizeof grbuf, &p))
+ return NULL;
+ return p;
+}
+
+struct group *getgrgid(
+ gid_t gid
+)
+{
+ struct group *p;
+
+ if(getgrgid_r(gid, &grent, grbuf, sizeof grbuf, &p))
+ return NULL;
+ return p;
+}
+
+struct group *getgrent(void)
+{
+ if (group_fp == NULL)
+ return NULL;
+ if (!_libcsupport_scangr(group_fp, &grent, grbuf, sizeof grbuf))
+ return NULL;
+ return &grent;
+}
+
+void setgrent(void)
+{
+ _libcsupport_pwdgrp_init();
+
+ if (group_fp != NULL)
+ fclose(group_fp);
+ group_fp = fopen("/etc/group", "r");
+}
+
+void endgrent(void)
+{
+ if (group_fp != NULL)
+ fclose(group_fp);
+}