| <html lang="en"> |
| <head> |
| <title>Scanning All Groups - The GNU C Library</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="The GNU C Library"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Group-Database.html#Group-Database" title="Group Database"> |
| <link rel="prev" href="Lookup-Group.html#Lookup-Group" title="Lookup Group"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| This file documents the GNU C library. |
| |
| This is Edition 0.12, last updated 2007-10-27, |
| of `The GNU C Library Reference Manual', for version |
| 2.8 (Sourcery G++ Lite 2011.03-41). |
| |
| Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, |
| 2003, 2007, 2008, 2010 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software Needs Free Documentation'' |
| and ``GNU Lesser General Public License'', the Front-Cover texts being |
| ``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A |
| copy of the license is included in the section entitled "GNU Free |
| Documentation License". |
| |
| (a) The FSF's Back-Cover Text is: ``You have the freedom to |
| copy and modify this GNU manual. Buying copies from the FSF |
| supports it in developing GNU and promoting software freedom.''--> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| <link rel="stylesheet" type="text/css" href="../cs.css"> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Scanning-All-Groups"></a> |
| <p> |
| Previous: <a rel="previous" accesskey="p" href="Lookup-Group.html#Lookup-Group">Lookup Group</a>, |
| Up: <a rel="up" accesskey="u" href="Group-Database.html#Group-Database">Group Database</a> |
| <hr> |
| </div> |
| |
| <h4 class="subsection">29.14.3 Scanning the List of All Groups</h4> |
| |
| <p><a name="index-scanning-the-group-list-3417"></a> |
| This section explains how a program can read the list of all groups in |
| the system, one group at a time. The functions described here are |
| declared in <samp><span class="file">grp.h</span></samp>. |
| |
| <p>You can use the <code>fgetgrent</code> function to read group entries from a |
| particular file. |
| |
| <!-- grp.h --> |
| <!-- SVID --> |
| <div class="defun"> |
| — Function: struct group * <b>fgetgrent</b> (<var>FILE *stream</var>)<var><a name="index-fgetgrent-3418"></a></var><br> |
| <blockquote><p>The <code>fgetgrent</code> function reads the next entry from <var>stream</var>. |
| It returns a pointer to the entry. The structure is statically |
| allocated and is overwritten on subsequent calls to <code>fgetgrent</code>. You |
| must copy the contents of the structure if you wish to save the |
| information. |
| |
| <p>The stream must correspond to a file in the same format as the standard |
| group database file. |
| </p></blockquote></div> |
| |
| <!-- grp.h --> |
| <!-- GNU --> |
| <div class="defun"> |
| — Function: int <b>fgetgrent_r</b> (<var>FILE *stream, struct group *result_buf, char *buffer, size_t buflen, struct group **result</var>)<var><a name="index-fgetgrent_005fr-3419"></a></var><br> |
| <blockquote><p>This function is similar to <code>fgetgrent</code> in that it reads the next |
| user entry from <var>stream</var>. But the result is returned in the |
| structure pointed to by <var>result_buf</var>. The first <var>buflen</var> bytes |
| of the additional buffer pointed to by <var>buffer</var> are used to contain |
| additional information, normally strings which are pointed to by the |
| elements of the result structure. |
| |
| <p>This stream must correspond to a file in the same format as the standard |
| group database file. |
| |
| <p>If the function returns zero <var>result</var> points to the structure with |
| the wanted data (normally this is in <var>result_buf</var>). If errors |
| occurred the return value is non-zero and <var>result</var> contains a null |
| pointer. |
| </p></blockquote></div> |
| |
| <p>The way to scan all the entries in the group database is with |
| <code>setgrent</code>, <code>getgrent</code>, and <code>endgrent</code>. |
| |
| <!-- grp.h --> |
| <!-- SVID, BSD --> |
| <div class="defun"> |
| — Function: void <b>setgrent</b> (<var>void</var>)<var><a name="index-setgrent-3420"></a></var><br> |
| <blockquote><p>This function initializes a stream for reading from the group data base. |
| You use this stream by calling <code>getgrent</code> or <code>getgrent_r</code>. |
| </p></blockquote></div> |
| |
| <!-- grp.h --> |
| <!-- SVID, BSD --> |
| <div class="defun"> |
| — Function: struct group * <b>getgrent</b> (<var>void</var>)<var><a name="index-getgrent-3421"></a></var><br> |
| <blockquote><p>The <code>getgrent</code> function reads the next entry from the stream |
| initialized by <code>setgrent</code>. It returns a pointer to the entry. The |
| structure is statically allocated and is overwritten on subsequent calls |
| to <code>getgrent</code>. You must copy the contents of the structure if you |
| wish to save the information. |
| </p></blockquote></div> |
| |
| <!-- grp.h --> |
| <!-- GNU --> |
| <div class="defun"> |
| — Function: int <b>getgrent_r</b> (<var>struct group *result_buf, char *buffer, size_t buflen, struct group **result</var>)<var><a name="index-getgrent_005fr-3422"></a></var><br> |
| <blockquote><p>This function is similar to <code>getgrent</code> in that it returns the next |
| entry from the stream initialized by <code>setgrent</code>. Like |
| <code>fgetgrent_r</code>, it places the result in user-supplied buffers |
| pointed to <var>result_buf</var> and <var>buffer</var>. |
| |
| <p>If the function returns zero <var>result</var> contains a pointer to the data |
| (normally equal to <var>result_buf</var>). If errors occurred the return |
| value is non-zero and <var>result</var> contains a null pointer. |
| </p></blockquote></div> |
| |
| <!-- grp.h --> |
| <!-- SVID, BSD --> |
| <div class="defun"> |
| — Function: void <b>endgrent</b> (<var>void</var>)<var><a name="index-endgrent-3423"></a></var><br> |
| <blockquote><p>This function closes the internal stream used by <code>getgrent</code> or |
| <code>getgrent_r</code>. |
| </p></blockquote></div> |
| |
| </body></html> |
| |