source: rtems/cpukit/libcsupport/src/getpwent.c @ b471854b

4.115
Last change on this file since b471854b was b471854b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/14 at 10:01:48

libcsupport: Split passwd/group support

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief User Database Access Routines
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  Copyright (c) 1999-2009 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
10 *  Copyright (c) 1999-2013 Joel Sherrill <joel.sherrill@OARcorp.com>
11 *  Copyright (c) 2000-2001 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
12 *  Copyright (c) 2002 Eric Norum <eric.norum@usask.ca>
13 *  Copyright (c) 2003 Till Straumann <strauman@slac.stanford.edu>
14 *  Copyright (c) 2012 Alex Ivanov <alexivanov97@gmail.com>
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#if HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include "pwdgrp.h"
26
27/*
28 * Static, thread-unsafe, buffers
29 */
30static FILE *passwd_fp;
31static char pwbuf[200];
32static struct passwd pwent;
33
34struct passwd *getpwnam(
35  const char *name
36)
37{
38  struct passwd *p;
39
40  if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p))
41    return NULL;
42  return p;
43}
44
45struct passwd *getpwuid(
46  uid_t uid
47)
48{
49  struct passwd *p;
50
51  if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p))
52    return NULL;
53  return p;
54}
55
56struct passwd *getpwent(void)
57{
58  if (passwd_fp == NULL)
59    return NULL;
60  if (!_libcsupport_scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf))
61    return NULL;
62  return &pwent;
63}
64
65void setpwent(void)
66{
67  _libcsupport_pwdgrp_init();
68
69  if (passwd_fp != NULL)
70    fclose(passwd_fp);
71  passwd_fp = fopen("/etc/passwd", "r");
72}
73
74void endpwent(void)
75{
76  if (passwd_fp != NULL)
77    fclose(passwd_fp);
78}
Note: See TracBrowser for help on using the repository browser.