Scroll to navigation

getgrent_r(3) Library Functions Manual getgrent_r(3)

NOM

getgrent_r, fgetgrent_r - Obtenir un enregistrement du fichier de groupes de manière réentrante

BIBLIOTHÈQUE

Bibliothèque C standard (libc-lc)

SYNOPSIS

#include <grp.h>
int getgrent_r(size_t size;
               struct group *restrict gbuf,
               char buf[restrict size], size_t size,
               struct group **restrict gbufp);
int fgetgrent_r(size_t size;
               FILE *restrict stream, struct group *restrict gbuf,
               char buf[restrict size], size_t size,
               struct group **restrict gbufp);

Exigences de macros de test de fonctionnalités pour la glibc (consulter feature_test_macros(7)) :

getgrent_r() :


_GNU_SOURCE

fgetgrent_r() :


Depuis la glibc 2.19 :
_POSIX_C_SOURCE >= 200809L
glibc 2.19 et antérieures :
_ATFILE_SOURCE

DESCRIPTION

Les fonctions getgrent_r() et fgetgrent_r() sont les versions réentrantes des fonctions getgrent(3) et fgetgrent(3). La première lit l'enregistrement de groupe suivant à partir du flux initialisé par setgrent(3). La seconde lit l'enregistrement de groupe suivant à partir du flux.

La structure group est définie dans <grp.h> comme ceci :


struct group {

char *gr_name; /* nom de groupe */
char *gr_passwd; /* mot de passe de groupe */
gid_t gr_gid; /* identifiant de groupe */
char **gr_mem; /* tableau de pointeurs de nom des membres de groupe
terminé par un pointeur NULL */ };

Pour plus d'informations à propos des champs de cette structure, consultez group(5).

The nonreentrant functions return a pointer to static storage, where this static storage contains further pointers to group name, password, and members. The reentrant functions described here return all of that in caller-provided buffers. First of all there is the buffer gbuf that can hold a struct group. And next the buffer buf of size size that can hold additional strings. The result of these functions, the struct group read from the stream, is stored in the provided buffer *gbuf, and a pointer to this struct group is returned in *gbufp.

VALEUR RENVOYÉE

On success, these functions return 0 and *gbufp is a pointer to the struct group. On error, these functions return an error value and *gbufp is NULL.

ERREURS

Il n'y a plus d'entrées.
L'espace tampon fourni est insuffisant. Veuillez essayer à nouveau avec un tampon plus grand.

ATTRIBUTS

Pour une explication des termes utilisés dans cette section, consulter attributes(7).

Interface Attribut Valeur
getgrent_r() Sécurité des threads MT-Unsafe race:grent locale
fgetgrent_r() Sécurité des threads MT-Safe

Dans la table ci-dessus, grent dans race:grent signifie que si des fonctions parmi setgrent(3), getgrent(3), endgrent(3) ou getgrent_r() sont utilisées en parallèle dans différents threads d'un programme, des situations de compétition de données pourraient se produire.

VERSIONS

D'autres systèmes utilisent le prototype


struct group *getgrent_r(struct group *grp, char tampon[.taille],

int taille);

ou mieux,


int getgrent_r(struct group *grp, char *tampon[.taille], int taille,

FILE **gr_fp);

STANDARDS

GNU.

HISTORIQUE

Ces fonctions sont écrites dans un style ressemblant à la version POSIX de fonctions comme getpwnam_r(3).

NOTES

La fonction getgrent_r() n'est pas vraiment réentrante puisqu'elle partage la position de lecture dans le flux avec tous les autres threads.

EXEMPLES

#define _GNU_SOURCE
#include <grp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFLEN 4096
int
main(void)
{

struct group grp;
struct group *grpp;
char buf[BUFLEN];
int i;
setgrent();
while (1) {
i = getgrent_r(&grp, buf, sizeof(buf), &grpp);
if (i)
break;
printf("%s (%jd):", grpp->gr_name, (intmax_t) grpp->gr_gid);
for (size_t j = 0; ; j++) {
if (grpp->gr_mem[j] == NULL)
break;
printf(" %s", grpp->gr_mem[j]);
}
printf("\n");
}
endgrent();
exit(EXIT_SUCCESS); }

VOIR AUSSI

fgetgrent(3), getgrent(3), getgrgid(3), getgrnam(3), putgrent(3), group(5)

TRADUCTION

La traduction française de cette page de manuel a été créée par Christophe Blaess <https://www.blaess.fr/christophe/>, Stéphan Rafin <stephan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, François Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard <fevrier@tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>, Thomas Huriaux <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>, Denis Barbier <barbier@debian.org>, David Prévot <david@tilapin.org> et Lucien Gentis <lucien.gentis@waika9.com>

Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.

Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à debian-l10n-french@lists.debian.org.

28 juin 2025 Pages du manuel de Linux 6.16