From 3f3f0ba1d1f14bfeba26020ddbfcefe52d82b370 Mon Sep 17 00:00:00 2001 From: Ben Asselstine Date: Sun, 18 Jan 2009 14:27:58 -0500 Subject: [PATCH] 2009-01-18 Ben Asselstine getusershell: new function: set_shells_file; new header: getusershell.h * lib/getusershell.c (set_shells_file): New function. * lib/getusershell.h: New File. * modules/getusershell (Include): Add getusershell.h. * users.txt: Add GNU Sysutils. --- lib/getusershell.c | 12 +++++++++++- lib/getusershell.h | 40 ++++++++++++++++++++++++++++++++++++++++ modules/getusershell | 2 +- users.txt | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 lib/getusershell.h diff --git a/lib/getusershell.c b/lib/getusershell.c index bea62a0..ebad8dc 100644 --- a/lib/getusershell.c +++ b/lib/getusershell.c @@ -66,6 +66,9 @@ static size_t default_index = 0; /* Input stream from the shells file. */ static FILE *shellstream = NULL; +/* The path to the file that contains the list of shells. */ +static char const *shells_file = SHELLS_FILE; + /* Line of input from the shells file. */ static char *line = NULL; @@ -90,7 +93,7 @@ getusershell (void) if (shellstream == NULL) { - shellstream = fopen (SHELLS_FILE, "r"); + shellstream = fopen (shells_file, "r"); if (shellstream == NULL) { /* No shells file. Use the default list. */ @@ -129,6 +132,13 @@ endusershell (void) } } +/* Set the path to the file holding the list of shells. */ +void +set_shells_file (char const *filename) +{ + shells_file = filename; +} + /* Read a line from STREAM, removing any newline at the end. Place the result in *NAME, which is malloc'd and/or realloc'd as necessary and can start out NULL, diff --git a/lib/getusershell.h b/lib/getusershell.h new file mode 100644 index 0000000..81c8e0a --- /dev/null +++ b/lib/getusershell.h @@ -0,0 +1,40 @@ +/* A more useful interface to getusershell. + + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GETUSERSHELL_H_ +# define GETUSERSHELL_H_ 1 + + +/* Return an entry from the shells file, ignoring comment lines. + If the file doesn't exist, use a default list of shells. + In any case, the returned string is in memory allocated through malloc. + Return NULL if there are no more entries. */ + +char * getusershell (void); + +/* Rewind the shells file. */ + +void setusershell (void); + +/* Close the shells file. */ + +void endusershell (void); + +/* Set the path to the file holding the list of shells. */ +void set_shells_file (char const *filename); + +#endif /* not GETUSERSHELL_H_ */ diff --git a/modules/getusershell b/modules/getusershell index 9ae7dca..4b0f3c0 100644 --- a/modules/getusershell +++ b/modules/getusershell @@ -18,7 +18,7 @@ gl_UNISTD_MODULE_INDICATOR([getusershell]) Makefile.am: Include: - +"getusershell.h" License: GPL diff --git a/users.txt b/users.txt index deb3127..b45dd15 100644 --- a/users.txt +++ b/users.txt @@ -53,6 +53,7 @@ The following packages appear to be using gnulib and gnulib-tool: radius http://cvs.sv.gnu.org/viewcvs/radius/radius/ sed http://cvs.savannah.gnu.org/viewcvs/sed/?root=sed shishi http://git.sv.gnu.org/gitweb/?p=shishi.git + sysutils http://svn.savannah.gnu.org/viewvc/?root=sysutils tar http://cvs.sv.gnu.org/viewcvs/tar/tar/ texinfo http://cvs.sv.gnu.org/viewcvs/texinfo/texinfo/ vc-dwim http://git.sv.gnu.org/gitweb/?p=vc-dwim.git -- 1.5.6.3