Annotation of 43BSDReno/lib/libc/gen/scandir.3, revision 1.1.1.1

1.1       root        1: .\" Copyright (c) 1983 Regents of the University of California.
                      2: .\" All rights reserved.
                      3: .\"
                      4: .\" Redistribution and use in source and binary forms are permitted provided
                      5: .\" that: (1) source distributions retain this entire copyright notice and
                      6: .\" comment, and (2) distributions including binaries display the following
                      7: .\" acknowledgement:  ``This product includes software developed by the
                      8: .\" University of California, Berkeley and its contributors'' in the
                      9: .\" documentation or other materials provided with the distribution and in
                     10: .\" all advertising materials mentioning features or use of this software.
                     11: .\" Neither the name of the University nor the names of its contributors may
                     12: .\" be used to endorse or promote products derived from this software without
                     13: .\" specific prior written permission.
                     14: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     15: .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     16: .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     17: .\"
                     18: .\"    @(#)scandir.3   6.6 (Berkeley) 6/24/90
                     19: .\"
                     20: .TH SCANDIR 3  "June 24, 1990"
                     21: .UC 5
                     22: .SH NAME
                     23: scandir, alphasort \- scan a directory
                     24: .SH SYNOPSIS
                     25: .nf
                     26: .ft B
                     27: #include <sys/types.h>
                     28: #include <dirent.h>
                     29: 
                     30: scandir(dirname, namelist, select, compar)
                     31: char *dirname;
                     32: struct direct ***namelist;
                     33: int (*select)();
                     34: int (*compar)();
                     35: 
                     36: alphasort(d1, d2)
                     37: void *d1, *d2;
                     38: .ft R
                     39: .fi
                     40: .SH DESCRIPTION
                     41: .I Scandir
                     42: reads the directory
                     43: .I dirname
                     44: and builds an array of pointers to directory
                     45: entries using
                     46: .IR malloc (3).
                     47: It returns the number of entries in the array.
                     48: A pointer to the array of directory entries is stored in the location
                     49: referenced by
                     50: .IR namelist .
                     51: .PP
                     52: The
                     53: .I select
                     54: parameter is a pointer to a user supplied subroutine which is called by
                     55: .I scandir
                     56: to select which entries are to be included in the array.
                     57: The select routine is passed a
                     58: pointer to a directory entry and should return a non-zero
                     59: value if the directory entry is to be included in the array.
                     60: If
                     61: .I select
                     62: is null, then all the directory entries will be included.
                     63: .PP
                     64: The
                     65: .I compar
                     66: parameter is a pointer to a user supplied subroutine which is passed to
                     67: .IR qsort (3)
                     68: to sort the completed array.
                     69: If this pointer is null, the array is not sorted.
                     70: .PP
                     71: .I Alphasort
                     72: is a routine which can be used for the
                     73: .I compar
                     74: parameter to sort the array alphabetically.
                     75: .PP
                     76: The memory allocated for the array can be deallocated with
                     77: .IR free (3),
                     78: by freeing each pointer in the array and then the array itself.
                     79: .SH "SEE ALSO"
                     80: directory(3), malloc(3), qsort(3), dir(5)
                     81: .SH DIAGNOSTICS
                     82: Returns \-1 if the directory cannot be opened for reading or if
                     83: .IR malloc (3)
                     84: cannot allocate enough memory to hold all the data structures.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.