.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 1993, David Metcalfe .\" Copyright 2008-2016, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH readdir 3 "8 février 2026" "Pages du manuel de Linux 6.18" .SH NOM readdir \- Consulter un répertoire .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP,\ \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBstruct dirent *readdir(DIR *\fP\fIdirp\fP\fB);\fP .fi .SH DESCRIPTION La fonction \fBreaddir\fP() renvoie un pointeur sur une structure \fIdirent\fP représentant l'entrée suivante du flux répertoire pointé par \fIdirp\fP. Elle renvoie NULL à la fin du répertoire ou en cas d'erreur. .P Dans l'implémentation de la glibc, la structure \fIdirent\fP est définie comme suit\ : .P .in +4n .EX struct dirent { ino_t d_ino; /* numéro d'inœud */ off_t d_off; /* pas une position ; consultez NOTES */ unsigned short d_reclen; /* longueur de cet enregistrement */ unsigned char d_type; /* type du fichier ; pas pris en charge par tous les types de système de fichiers */ char d_name[256]; /* nom du fichier terminé par l'octet NULL */ }; .EE .in .P The only fields in the \fIdirent\fP structure that are mandated by POSIX.1 are \&\fI.d_name\fP and \fI.d_ino\fP. The other fields are unstandardized, and not present on all systems; see VERSIONS. .P Les champs de la structure \fIdirent\fP sont les suivants : .TP \&\fI.d_ino\fP This is the inode number of the file in the filesystem containing the directory on which \fBreaddir\fP() was called. If the directory entry is a mount point, then \fI.d_ino\fP differs from \fI.st_ino\fP returned by \fBstat\fP(2) on this file: \fI.d_ino\fP is the inode number of the mount point, while \&\fI.st_ino\fP is the inode number of the root directory of the mounted filesystem. .TP \&\fI.d_off\fP .\" https://lwn.net/Articles/544298/ The value returned in \fI.d_off\fP is the same as would be returned by calling \fBtelldir\fP(3) at the current position in the directory stream. Be aware that despite its type and name, the \fI.d_off\fP field is seldom any kind of directory offset on modern filesystems. Applications should treat this field as an opaque value, making no assumptions about its contents; see also \fBtelldir\fP(3). .TP \&\fI.d_reclen\fP La taille (en octets) de l'enregistrement renvoyé. Elle peut ne pas correspondre à la taille de la définition de la structure montrée plus haut ; voir VERSIONS. .TP \&\fI.d_type\fP Ce champ contient une valeur indiquant le type du fichier, permettant d'éviter le coût d'un appel à \fBlstat\fP(2) si d'autres actions dépendent du type du fichier. .IP When a suitable feature test macro is defined (\fB_DEFAULT_SOURCE\fP since glibc 2.19, or \fB_BSD_SOURCE\fP on glibc 2.19 and earlier), glibc defines the following macro constants for the value returned in \fI.d_type\fP: .RS .TP 12 \fBDT_BLK\fP Il s'agit d'un périphérique bloc. .TP \fBDT_CHR\fP Il s'agit d'un périphérique caractère. .TP \fBDT_DIR\fP Il s'agit d'un répertoire .TP \fBDT_FIFO\fP Il s'agit d'un tube nommé (FIFO). .TP \fBDT_LNK\fP Il s'agit d'un lien symbolique. .TP \fBDT_REG\fP Il s'agit d'un fichier ordinaire. .TP \fBDT_SOCK\fP Il s'agit d'un socket de domaine UNIX. .TP \fBDT_UNKNOWN\fP Le type du fichier n'a pu être déterminé. .RE .IP .\" kernel 2.6.27 .\" The same sentence is in getdents.2 Currently, only some filesystems (among them: Btrfs, ext2, ext3, and ext4) have full support for returning the file type in \fI.d_type\fP. All applications must properly handle a return of \fBDT_UNKNOWN\fP. .TP \&\fI.d_name\fP Ce champ contient le nom de fichier terminé par l'octet NULL. \fIVoir VERSIONS\fP. .P Les donnes renvoyées par \fBreaddir\fP() sont écrasées lors de l'appel suivant à \fBreaddir\fP() sur le même flux répertoire. .SH "VALEUR RENVOYÉE" En cas de succès, \fBreaddir\fP() renvoie un pointeur sur une structure \fIdirent\fP (cette structure peut avoir été allouée statiquement ; n'essayez pas de la désallouer avec \fBfree\fP(3)). .P Lorsque la fin du flux répertoire est atteinte, NULL est renvoyé et \fIerrno\fP n'est pas modifiée. En cas d'erreur, NULL est renvoyé et \fIerrno\fP contient le code d'erreur. Pour distinguer la fin du flux d'une erreur, il faut assigner \fIerrno\fP à zéro avant d'appeler \fBreaddir()\fP puis ensuite tester la valeur de \fIerrno\fP si NULL est renvoyé. .SH ERREURS .TP \fBEBADF\fP Le descripteur de flux répertoire \fIdirp\fP n'est pas valable. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interface Attribut Valeur T{ .na .nh \fBreaddir\fP() T} Sécurité des threads MT\-Unsafe race:dirstream .TE .P .\" FIXME . .\" http://www.austingroupbugs.net/view.php?id=696 Dans la spécification POSIX.1 actuelle (POSIX.1\-2008), il n'est pas requis que \fBreaddir\fP(3) soit sûr vis\-à\-vis des threads. Cependant, dans les implémentations modernes, incluant la glibc, des appels concurrents à \fBreaddir\fP(3) pour des flux répertoire différents sont sûrs vis\-à\-vis des threads. Dans le cas où de multiples threads doivent lire depuis un flux de répertoire identique, l'utilisation de \fBreaddir\fP(3) avec une synchronisation externe est toujours préférable à l'utilisation de \fBreaddir_r\fP(3). Il est attendu qu'une future version de POSIX.1 demande que \fBreaddir\fP() soit sûr vis\-à\-vis des threads lorsqu'il est employé simultanément sur des flux répertoire différents. .SH VERSIONS .\" POSIX.1-2001, POSIX.1-2008 .\" Only the fields \fI.d_name\fP and (as an XSI extension) \fI.d_ino\fP are specified in POSIX.1. Other than Linux, the \fI.d_type\fP field is available mainly only on BSD systems. The remaining fields are available on many, but not all systems. Under glibc, programs can check for the availability of the fields not defined in POSIX.1 by testing whether the macros \fB_DIRENT_HAVE_D_NAMLEN\fP, \fB_DIRENT_HAVE_D_RECLEN\fP, \fB_DIRENT_HAVE_D_OFF\fP, or \fB_DIRENT_HAVE_D_TYPE\fP are defined. .SS "The \f[I].d_name\fB field" The \fIdirent\fP structure definition shown above is taken from the glibc headers, and shows the \fI.d_name\fP field with a fixed size. .P \fIWarning\fP: applications should avoid any dependence on the size of the \&\fI.d_name\fP field. POSIX defines it as \fIchar\ d_name[]\fP, a character array of unspecified size, with at most \fBNAME_MAX\fP characters preceding the terminating null byte (\[aq]\[rs]0\[aq]). .P POSIX.1 explicitly notes that this field should not be used as an lvalue. The standard also notes that the use of \fIsizeof(.d_name)\fP is incorrect; use \fIstrlen(.d_name)\fP instead. (On some systems, this field is defined as \fIchar\ d_name[1]\fP!) By implication, the use \fIsizeof(struct dirent)\fP to capture the size of the record including the size of \fI.d_name\fP is also incorrect. .P Notez que bien que l'appel .P .in +4n .EX fpathconf(fd, _PC_NAME_MAX) .EE .in .P returns the value 255 for most filesystems, on some filesystems (e.g., CIFS, Windows SMB servers), the null\-terminated filename that is (correctly) returned in \fI.d_name\fP can actually exceed this size. In such cases, the \&\fI.d_reclen\fP field will contain a value that exceeds the size of the glibc \fIdirent\fP structure shown above. .SH NORMES POSIX.1\-2008. .SH HISTORIQUE POSIX.1\-2001, SVr4, 4.3BSD. .SH NOTES Un flux répertoire est ouvert avec \fBopendir\fP(3). .P L'ordre dans lequel les noms de fichier sont lus par des appels successifs à \fBreaddir\fP() dépend de l'implémentation du système de fichiers ; il est peu probable que les noms soient triés d'une quelconque façon. .SH "VOIR AUSSI" \fBgetdents\fP(2), \fBread\fP(2), \fBclosedir\fP(3), \fBdirfd\fP(3), \fBftw\fP(3), \fBoffsetof\fP(3), \fBopendir\fP(3), \fBreaddir_r\fP(3), \fBrewinddir\fP(3), \fBscandir\fP(3), \fBseekdir\fP(3), \fBtelldir\fP(3) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot , Frédéric Hantrais et Grégoire Scano . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .