diff options
author | Robert de Bath <rdebath@poboxes.com> | 1997-02-25 20:42:19 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:38:07 +0200 |
commit | 4c36e9a0c125ccfff37aa440dab2cf58c4152fff (patch) | |
tree | a5d9c84ba2661029ddb2223dacd50529a361c3d5 /libc/getent/getgrnam.c | |
parent | f8de35da65c5d93bb733073cf40da154bc1c0748 (diff) | |
parent | 9696d7b0e1f3a1b0f5fd4a0428eb75afe8ad4ed6 (diff) | |
download | dev86-4c36e9a0c125ccfff37aa440dab2cf58c4152fff.tar.gz |
Import Dev86src-0.0.11.tar.gzv0.0.11
Diffstat (limited to 'libc/getent/getgrnam.c')
-rw-r--r-- | libc/getent/getgrnam.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libc/getent/getgrnam.c b/libc/getent/getgrnam.c new file mode 100644 index 0000000..e6c27fc --- /dev/null +++ b/libc/getent/getgrnam.c @@ -0,0 +1,51 @@ +/* + * getgrnam.c - This file is part of the libc-8086/grp package for ELKS, + * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <grp.h> + +struct group * +getgrnam(const char * name) +{ + int grp_fd; + struct group * group; + + if (name==NULL) + { + errno=EINVAL; + return NULL; + } + + if ((grp_fd=open("/etc/group", O_RDONLY))<0) + return NULL; + + while ((group=__getgrent(grp_fd))!=NULL) + if (!strcmp(group->gr_name, name)) + { + close(grp_fd); + return group; + } + + close(grp_fd); + return NULL; +} |