3 /* From OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp */
6 * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 * Sponsored in part by the Defense Advanced Research Projects
21 * Agency (DARPA) and Air Force Research Laboratory, Air Force
22 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
24 #include <sys/cdefs.h>
30 #include <sys/types.h>
38 ftw(const char *path
, int (*fn
)(const char *, const struct stat
*, int),
42 char * const paths
[2] = { __UNCONST(path
), NULL
};
45 int fnflag
, error
, sverrno
;
47 /* XXX - nfds is currently unused */
48 if (nfds
< 1 || nfds
> OPEN_MAX
) {
53 ftsp
= fts_open(paths
, FTS_COMFOLLOW
| FTS_NOCHDIR
, NULL
);
57 while ((cur
= fts_read(ftsp
)) != NULL
) {
58 switch (cur
->fts_info
) {
66 /* we only visit in preorder */
87 error
= fn(cur
->fts_path
, cur
->fts_statp
, fnflag
);
93 if (fts_close(ftsp
) != 0 && error
== 0)