.\" -*- coding: UTF-8 -*- '\" t .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" The pieces on scandirat(3) were copyright and licensed as follows. .\" .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: GPL-2.0-or-later .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH scandir 3 "17 mai 2025" "Pages du manuel de Linux 6.15" .SH NOM scandir, scandirat, alphasort, versionsort \- Sélectionner des éléments d'un répertoire .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP,\ \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBint scandir(const char *restrict \fP\fIdirp\fP\fB,\fP \fB struct dirent ***restrict \fP\fInamelist\fP\fB,\fP \fB typeof(int (const struct dirent *)) *\fP\fIfilter\fP\fB,\fP \fBtypeof(int (const struct dirent **, const struct dirent **))\fP \fB *\fP\fIcompar\fP\fB);\fP .P \fBint alphasort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP \fBint versionsort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP .P \fB#include \fP /* Définition des constantes AT_* */ \fB#include \fP .P \fBint scandirat(int \fP\fIdirfd\fP\fB, const char *restrict \fP\fIdirp\fP\fB,\fP \fB struct dirent ***restrict \fP\fInamelist\fP\fB,\fP \fB typeof(int (const struct dirent *)) *\fP\fIfilter\fP\fB,\fP \fBtypeof(int (const struct dirent **, const struct dirent **))\fP \fB *\fP\fIcompar\fP\fB);\fP .fi .P .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7)) : .RE .P \fBscandir\fP(), \fBalphasort\fP() : .nf /* Depuis la glibc 2.10 : */ _POSIX_C_SOURCE\ >=\ 200809L || /* glibc <= 2.19 : */ _BSD_SOURCE .fi .P \fBversionsort\fP() : .nf _GNU_SOURCE .fi .P \fBscandirat\fP() : .nf _GNU_SOURCE .fi .SH DESCRIPTION The \fBscandir\fP() function scans the directory \fIdirp\fP, calling \fIfilter\fP() on each directory entry. Entries for which \fIfilter\fP() returns nonzero are stored in strings allocated via \fBmalloc\fP(3), sorted using \fBqsort\fP(3) with the comparison function \fIcompar\fP(), and collected in array \fInamelist\fP which is allocated via \fBmalloc\fP(3). If \fIfilter\fP is NULL, all entries are selected. .P Les fonctions \fBalphasort\fP() et \fBversionsort\fP() peuvent être utilisées comme la fonction de comparaison \fIcompar\fP. La première trie les entrées du répertoire en ordre alphabétique en utilisant \fBstrcoll\fP(3), la seconde en utilisant \fBstrverscmp\fP(3) sur les chaînes \fI(*a)\->d_name\fP et \fI(*b)\->d_name\fP. .SS scandirat() La fonction \fBscandirat\fP() fonctionne exactement comme \fBscandir\fP(), les seules différences étant décrites ici. .P If \fIdirp\fP is relative, then it is interpreted relative to the directory referred to by the file descriptor \fIdirfd\fP (rather than relative to the current working directory of the calling process, as is done by \fBscandir\fP() for a relative pathname). .P Si \fIdirp\fP est relatif et que \fIdirfd\fP est la valeur particulière \fBAT_FDCWD\fP, alors \fIdirp\fP est considéré relatif au répertoire de travail actuel du processus appelant (comme \fBscandir\fP()). .P Si \fIdirp\fP est absolu, alors \fIdirfd\fP est ignoré. .P Consultez \fBopenat\fP(2) pour une explication sur la nécessité de \fBscandirat\fP(). .SH "VALEUR RENVOYÉE" La fonction \fBscandir\fP() renvoie le nombre d'entrées du répertoire sélectionné si elle réussit, ou \fB\-1\fP si elle échoue, avec \fIerrno\fP contenant le code d'erreur. .P Les fonctions \fBalphasort\fP() et \fBversionsort\fP() renvoient un entier négatif, nul ou positif si le premier argument est respectivement inférieur, égal ou supérieur au second. .SH ERREURS .TP \fBEBADF\fP (\fBscandirat\fP()) \fIdirp\fP est relatif mais \fIdirfd\fP n'est ni \fBAT_FDCWD\fP, ni un descripteur de fichier valable. .TP \fBENOENT\fP Le chemin n'existe pas dans \fIdirp\fP. .TP \fBENOMEM\fP Pas assez de mémoire pour terminer l'opération. .TP \fBENOTDIR\fP Le chemin n'est pas un répertoire de \fIdirp\fP. .TP \fBENOTDIR\fP (\fBscandirat\fP()) \fIdirp\fP is relative and \fIdirfd\fP is a file descriptor referring to a file other than a directory. .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 \fBscandir\fP(), \fBscandirat\fP() T} Sécurité des threads MT\-Safe T{ .na .nh \fBalphasort\fP(), \fBversionsort\fP() T} Sécurité des threads MT\-Safe locale .TE .SH STANDARDS .TP \fBalphasort\fP() .TQ \fBscandir\fP() POSIX.1\-2008. .TP \fBversionsort\fP() .TQ \fBscandirat\fP() GNU. .SH HISTORIQUE .TP \fBalphasort\fP() .TQ \fBscandir\fP() 4.3BSD, POSIX.1\-2008. .TP \fBversionsort\fP() glibc 2.1. .TP \fBscandirat\fP() .\" .P .\" The functions .\" .BR scandir () .\" and .\" .BR alphasort () .\" are from 4.3BSD, and have been available under Linux since libc4. .\" Libc4 and libc5 use the more precise prototype .\" .sp .\" .nf .\" int alphasort(const struct dirent ** a, .\" const struct dirent **b); .\" .fi .\" .sp .\" but glibc 2.0 returns to the imprecise BSD prototype. glibc 2.15. .SH NOTES Depuis la version 2.1 de la glibc, la fonction \fBalphasort\fP() invoque \fBstrcoll\fP(3). Dans les versions précédentes, elle appelait \fBstrcmp\fP(3). .P Avant la glibc 2.10, les deux arguments de \fBalphasort\fP() et \fBversionsort\fP() sont typés comme des \fIconst void\ *\fP. Dans la standardisation par POSIX.1\-2008 de \fBalphasort\fP(), le type de l'argument est le type sûr \fIconst struct dirent\ **\fP, et la glibc 2.10 change cette définition d'\fBalphasort\fP() (et le non standard \fBversionsort\fP()) pour se conformer à la norme. .SH EXEMPLES .\" Le programme suivant imprime une liste des fichiers dans le répertoire courant dans l'ordre inverse. .SS "Source du programme" .\" SRC BEGIN (scandir.c) \& .EX #define _DEFAULT_SOURCE #include #include #include \& int main(void) { struct dirent **namelist; int n; \& n = scandir(".", &namelist, NULL, alphasort); if (n == \-1) { perror("scandir"); exit(EXIT_FAILURE); } \& while (n\-\-) { printf("%s\[rs]n", namelist[n]\->d_name); free(namelist[n]); } free(namelist); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBclosedir\fP(3), \fBfnmatch\fP(3), \fBopendir\fP(3), \fBreaddir\fP(3), \fBrewinddir\fP(3), \fBseekdir\fP(3), \fBstrcmp\fP(3), \fBstrcoll\fP(3), \fBstrverscmp\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 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 .