.\" -*- coding: UTF-8 -*- .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 18:26:16 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Thu Apr 11 17:11:33 1996 by Andries Brouwer (aeb@cwi.nl): .\" Corrected type of compar routines, as suggested by .\" Miguel Barreiro (enano@avalon.yaix.es). Added example. .\" Modified Sun Sep 24 20:15:46 2000 by aeb, following Petter Reinholdtsen. .\" Modified 2001-12-26 by aeb, following Joey. Added versionsort. .\" .\" The pieces on scandirat(3) were copyright and licensed as follows. .\" .\" Copyright (c) 2012, Mark R. Bannister .\" based on text in mkfifoat.3 Copyright (c) 2006, Michael Kerrisk .\" .\" %%%LICENSE_START(GPLv2+_DOC_FULL) .\" This is free documentation; 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 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual 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 manual; if not, see .\" . .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH SCANDIR 3 "15 septembre 2017" GNU "Manuel du programmeur Linux" .SH NOM scandir, scandirat, alphasort, versionsort \- Sélectionner des éléments d'un répertoire .SH SYNOPSIS .nf \fB#include \fP .PP \fBint scandir(const char *\fP\fIdirp\fP\fB, struct dirent ***\fP\fInamelist\fP\fB,\fP .RS \fBint (*\fP\fIfilter\fP\fB)(const struct dirent *),\fP \fBint (*\fP\fIcompar\fP\fB)(const struct dirent **, const struct dirent **));\fP .RE .PP \fBint alphasort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP .PP \fBint versionsort(const struct dirent **\fP\fIa\fP\fB, const struct dirent **\fP\fIb\fP\fB);\fP \fB#include \fP /* Définition des constantes AT_* */ \fB#include \fP .PP .fi \fBint scandirat(int \fP\fIdirfd\fP\fB, const char *\fP\fIdirp\fP\fB,\fP \fBstruct dirent ***\fP\fInamelist\fP\fB,\fP .nf .RS \fBint (*\fP\fIfilter\fP\fB)(const struct dirent *),\fP \fBint (*\fP\fIcompar\fP\fB)(const struct dirent **, const struct dirent **));\fP .RE .fi .PP .in -4n Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7))\ : .in .PP \fBscandir\fP(), \fBalphasort\fP()\ : .br .RS 4 .PD 0 .ad b /* Since glibc 2.10: */ _POSIX_C_SOURCE\ >=\ 200809L || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE .PD .RE .PP \fBversionsort\fP()\ : _GNU_SOURCE .PP \fBscandirat\fP()\ : _GNU_SOURCE .SH DESCRIPTION La fonction \fBscandir\fP() examine le répertoire \fIdirp\fP, en appelant \fIfilter\fP() pour chaque élément rencontré. Les entrées pour lesquelles \fIfilter\fP() renvoie une valeur non nulle sont stockées dans une table allouée avec \fBmalloc\fP(3), triée avec \fBqsort\fP(3) en utilisant la fonction de comparaison \fIcompar\fP(), puis regroupées dans une table \fInamelist\fP allouée avec \fBmalloc\fP(3). Si \fIfilter\fP est NULL, toutes les entrées sont sélectionnées. .PP Les fonctions \fBalphasort\fP() et \fBversionsort\fP() peuvent être utilisées comme 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(3), les seules différences étant décrites ici. .PP Si le nom de chemin donné dans \fIdirp\fP est relatif, il est considéré relatif au répertoire référencé par le descripteur de fichier \fIdirfd\fP (plutôt que relatif au répertoire de travail actuel du processus appelant, comme avec \fBscandir\fP() pour un nom de chemin relatif). .PP 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()). .PP Si \fIdirp\fP est absolu, alors \fIdirfd\fP est ignoré. .PP 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 de répertoires sélectionnées s'il réussit, ou \-1 s'il échoue, avec \fIerrno\fP qui contient le code d'erreur. .PP 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 \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. .PP Les erreurs supplémentaires suivantes peuvent se produire avec \fBscandirat\fP(). .TP \fBEBADF\fP \fIdirfd\fP n'est pas un descripteur de fichier valable. .TP \fBENOTDIR\fP \fIdirp\fP est un chemin relatif et \fIdirfd\fP est un descripteur de fichier référençant un fichier qui n'est pas un répertoire. .SH VERSIONS \fBversionsort\fP() a été ajoutée à la glibc dans la version 2.1. .PP \fBscandirat\fP() a été ajoutée à la glibc dans la version\ 2.15. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lbw26 lb lb l l l. Interface Attribut Valeur T{ \fBscandir\fP(), \fBscandirat\fP() T} Sécurité des threads MT\-Safe T{ \fBalphasort\fP(), \fBversionsort\fP() T} Sécurité des threads MT\-Safe locale .TE .sp 1 .SH CONFORMITÉ \fBalphasort\fP(), \fBscandir\fP()\ : BSD\ 4.3, POSIX.1\-2008. .PP .\" .LP .\" 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. \fBversionsort\fP() et \fBscandirat\fP() sont des extensions GNU. .SH NOTES Depuis la glibc 2.1, la fonction \fBalphasort\fP() invoque \fBstrcoll\fP(3). Dans les versions précédentes, elle appelait \fBstrcmp\fP(3). .PP Before glibc 2.10, the two arguments of \fBalphasort\fP() and \fBversionsort\fP() were typed as \fIconst void\ *\fP. When \fBalphasort\fP() was standardized in POSIX.1\-2008, the argument type was specified as the type\-safe \fIconst struct dirent\ **\fP, and glibc 2.10 changed the definition of \fBalphasort\fP() (and the nonstandard \fBversionsort\fP()) to match the standard. .SH EXEMPLE .\" The program below prints a list of the files in the current directory in reverse order. .SS "Source du programme" \& .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\en", namelist[n]\->d_name); free(namelist[n]); } free(namelist); exit(EXIT_SUCCESS); } .EE .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) .SH COLOPHON Cette page fait partie de la publication\ 5.04 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .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 et David Prévot . 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. 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 .