.\" -*- coding: UTF-8 -*- .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" 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. .\" .\" 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. .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH SCANDIR 3 "26. April 2012" GNU Linux\-Programmierhandbuch .SH BEZEICHNUNG scandir, alphasort, versionsort \- durchsucht ein Verzeichnis nach passenden Einträgen .SH ÜBERSICHT .nf \fB#include \fP .sp \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 .sp \fBint alphasort(const void *\fP\fIa\fP\fB, const void *\fP\fIb\fP\fB);\fP .sp \fBint versionsort(const void *\fP\fIa\fP\fB, const void *\fP\fIb\fP\fB);\fP .fi .sp .in -4n Mit Glibc erforderliche Makros (siehe \fBfeature_test_macros\fP(7)): .in .sp \fBscandir\fP(), \fBalphasort\fP(): _BSD_SOURCE || _SVID_SOURCE .br \fBversionsort\fP(): _GNU_SOURCE .SH BESCHREIBUNG Die Funktion \fBscandir\fP() durchsucht das Verzeichnis \fIdirp\fP und ruft für jeden Verzeichniseintrag \fBfilter\fP() auf. Einträge, für die \fBfilter()\fP einen Wert ungleich 0 zurückgibt, werden in Zeichenketten gespeichert, derenSpeicher mit \fBmalloc\fP(3) reserviert wird. Danach werden die Zeichenkettenmit \fBqsort\fP(3) unter Verwendung der Vergleichsfunktion \fBcompar\fP() sortiert und im Feld \fInamelist\fP gesammelt, dessen Speicher ebenfalls mit \fBmalloc\fP(3) reserviert wird. Falls \fIfilter\fP gleich NULL ist, werden alle Einträge ausgewählt. .LP Die Funktionen \fBalphasort\fP() und \fBversionsort\fP() können als die Vergleichsfunktion \fIcompar\fP() benutzt werden. Die erste sortiert die Verzeichniseinträge mittels \fBstrcoll\fP(3), die letztere \fBstrverscmp\fP(3) auf den Zeichenketten \fI(*a)\->d_name\fP and \fI(*b)\->d_name\fP. .SH RÜCKGABEWERT Die Funktion \fBscandir\fP() liefert die Anzahl ausgewählter Verzeichniseinträge oder im Fehlerfall \-1 zurück. .PP Die Funktionen \fBalphasort\fP() und \fBversionsort\fP() liefern eine Zahl kleiner als Null, Null, oder größer als Null zurück, wenn das erste Argument entsprechend als kleiner, gleich oder größer als das zweite Argument angesehen wird. .SH FEHLER .TP \fBENOENT\fP Der Pfad in \fIdirp\fP existiert nicht. .TP \fBENOMEM\fP Zu wenig Speicher um den Vorgang zu beenden. .TP \fBENOTDIR\fP Der Pfad in \fIdirp\fP ist kein Verzeichnis. .SH VERSIONEN \fBversionsort\fP() wurde der Glibc in Version 2.1 hinzugefügt. .SH "KONFORM ZU" \fBalphasort\fP() und \fBscandir\fP() werden in POSIX.1\-2008 beschrieben und sind weithin verfügbar. \fBversionsort\fP() ist eine GNU\-Erweiterung. .LP Die Funktion \fBscandir\fP() und \fBalphasort\fP() stammen aus 4.3BSD und waren unter Linux seit Libc4 verfügbar. Libc4 und Libc5 verwenden den genaueren Prototyp .sp .nf int alphasort(const struct dirent ** a, const struct dirent **b); .fi .sp aber Glibc 2.0 kehrt zum ungenauen BSD\-Prototyp zurück. .LP Die Funktion \fBversionsort\fP() ist eine GNU\-Erweiterung und seit Glibc 2.1 verfügbar. .LP Seit Glibc 2.1 verwendet \fBalphasort\fP() \fBstrcoll\fP(3); früher nutzte sie \fBstrcmp\fP(3). .SH BEISPIEL .nf #define _SVID_SOURCE /* Ausgabe der Dateien im aktuellen Verzeichnis in umgekehrter Reihenfolge */ #include int main(void) { struct dirent **Namensliste; int n; n = scandir(".", &Namensliste, NULL, alphasort); if (n < 0) perror("scandir"); else { while (n\-\-) { printf("%s\en", Namensliste[n]\->d_name); free(Namensliste[n]); } free(Namensliste); } } .fi .SH "SIEHE AUCH" \fBclosedir\fP(3), \fBfnmatch\fP(3), \fBopendir\fP(3), \fBreaddir\fP(3), \fBrewinddir\fP(3), \fBscandirat\fP(3), \fBseekdir\fP(3), \fBstrcmp\fP(3), \fBstrcoll\fP(3), \fBstrverscmp\fP(3), \fBtelldir\fP(3) .SH KOLOPHON Diese Seite ist Teil der Veröffentlichung 3.42 des Projekts Linux\-\fIman\-pages\fP. Eine Beschreibung des Projekts und Informationen, wie Fehler gemeldet werden können, finden sich unter http://www.kernel.org/doc/man\-pages/. .SH ÜBERSETZUNG Die deutsche Übersetzung dieser Handbuchseite wurde von Markus Kaufmann und Martin Eberhard Schauer erstellt. Diese Übersetzung ist Freie Dokumentation; lesen Sie die GNU General Public License Version 3 oder neuer bezüglich der Copyright-Bedingungen. Es wird KEINE HAFTUNG übernommen. Wenn Sie Fehler in der Übersetzung dieser Handbuchseite finden, schicken Sie bitte eine E-Mail an .