Debian Codegraph @

upstream/debian-unstable/man3/readdir.3am

raw
1 .TH READDIR 3am "June 02 2023" "Free Software Foundation" "GNU Awk Extension Modules"
2 .SH NAME
3 readdir \- directory input parser for gawk
4 .SH SYNOPSIS
5 .ft CW
6 @load "readdir"
7 .sp
8 BEGIN { PROCINFO["readdir_override"] = \fIany_value\fP } # optional
9 .ft R
10 .SH DESCRIPTION
11 The
12 .I readdir
13 extension
14 adds an input parser for directories.
15 .PP
16 When this extension is in use, instead of skipping directories named
17 on the command line (or with
18 .BR getline ),
19 they are read, with each entry returned as a record.
20 .PP
21 The record consists of three fields
22 separated by forward slash characters.
23 The first two are the inode number and the
24 filename, and
25 the third field is a single letter indicating the type of the
26 file:
27 .B f
28 for file,
29 .B d
30 for directory,
31 .B b
32 for a block device,
33 .B c
34 for a character device,
35 .B p
36 for a FIFO,
37 .B l
38 for a symbolic link, or
39 .B s
40 for a socket.
41 .PP
42 On systems where the directory entry contains the file type, the third
43 field is filled in from that information.
44 On systems without the file type information, the extension falls back
45 to calling
46 .IR stat (2),
47 in order to provide the information.
48 Thus the third field should never be
49 .BR u " (unknown)."
50 .PP
51 Normally, when reading directories, you should set
52 .B FS
53 equal to \fB"/"\fP. However, you may instead chose to create
54 \fBPROCINFO["readdir_override"]\fP (with any value). If this element
55 exists when the directory is opened, then the extension automatically
56 sets the fields in each record for you.
57 .PP
58 By default, if a directory cannot be opened (due to permission problems,
59 for example),
60 .I gawk
61 will exit.
62 As with regular files, this situation can be handled using a
63 .B BEGINFILE
64 rule that checks
65 .B ERRNO
66 and prints an error or otherwise handles the problem.
67 .\" .SH BUGS
68 .SH EXAMPLE
69 .ft CW
70 .nf
71 @load "readdir"
72 \&...
73 BEGIN { FS = "/" }
74 { print "file name is", $2 }
75 .fi
76 .ft R
77 .SH "SEE ALSO"
78 .IR "GAWK: Effective AWK Programming" ,
79 .IR filefuncs (3am),
80 .IR fnmatch (3am),
81 .IR fork (3am),
82 .IR inplace (3am),
83 .IR ordchr (3am),
84 .IR readfile (3am),
85 .IR revoutput (3am),
86 .IR rwarray (3am),
87 .IR time (3am).
88 .PP
89 .IR opendir (3),
90 .IR readdir (3),
91 .IR stat (2).
92 .SH AUTHOR
93 Arnold Robbins,
94 .BR [email protected] .
95 .SH COPYING PERMISSIONS
96 Copyright \(co 2012, 2013, 2018, 2019, 2023
97 Free Software Foundation, Inc.
98 .PP
99 Permission is granted to make and distribute verbatim copies of
100 this manual page provided the copyright notice and this permission
101 notice are preserved on all copies.
102 .ig
103 Permission is granted to process this file through troff and print the
104 results, provided the printed document carries copying permission
105 notice identical to this one except for the removal of this paragraph
106 (this paragraph not being relevant to the printed manual page).
107 ..
108 .PP
109 Permission is granted to copy and distribute modified versions of this
110 manual page under the conditions for verbatim copying, provided that
111 the entire resulting derived work is distributed under the terms of a
112 permission notice identical to this one.
113 .PP
114 Permission is granted to copy and distribute translations of this
115 manual page into another language, under the above conditions for
116 modified versions, except that this permission notice may be stated in
117 a translation approved by the Foundation.
118 .\" vim: set filetype=nroff :