Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add Todd Miller's ftw(3) and nftw(3) file-tree walking funct...



details:   https://anonhg.NetBSD.org/src/rev/6bf2d83ec682
branches:  trunk
changeset: 586752:6bf2d83ec682
user:      agc <agc%NetBSD.org@localhost>
date:      Fri Dec 30 23:07:31 2005 +0000

description:
Add Todd Miller's ftw(3) and nftw(3) file-tree walking functionality,
from OpenBSD.

Bump libc minor to 136.

diffstat:

 distrib/sets/lists/base/shl.mi |    6 +-
 distrib/sets/lists/comp/mi     |    7 +-
 include/Makefile               |    4 +-
 include/ftw.h                  |   62 ++++++++++++
 lib/libc/gen/Makefile.inc      |   10 +-
 lib/libc/gen/ftw.3             |  211 +++++++++++++++++++++++++++++++++++++++++
 lib/libc/gen/ftw.c             |   98 +++++++++++++++++++
 lib/libc/gen/nftw.c            |  114 ++++++++++++++++++++++
 lib/libc/shlib_version         |    4 +-
 9 files changed, 504 insertions(+), 12 deletions(-)

diffs (truncated from 648 to 300 lines):

diff -r 086240e1bd65 -r 6bf2d83ec682 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi    Fri Dec 30 16:12:11 2005 +0000
+++ b/distrib/sets/lists/base/shl.mi    Fri Dec 30 23:07:31 2005 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: shl.mi,v 1.329 2005/12/20 21:34:29 christos Exp $
+# $NetBSD: shl.mi,v 1.330 2005/12/30 23:07:32 agc Exp $
 # Note: libtermcap and libtermlib are hardlinked and share the same version.
-./lib/libc.so.12.135                           base-sys-shlib
+./lib/libc.so.12.136                           base-sys-shlib
 ./lib/libcrypt.so.0.2                          base-sys-shlib
 ./lib/libcrypto.so.3.0                         base-crypto-shlib       crypto
 ./lib/libedit.so.2.9                           base-sys-shlib
@@ -34,7 +34,7 @@
 ./usr/lib/libasn1.so.6.1                       base-krb5-shlib         kerberos
 ./usr/lib/libbsdmalloc.so.0.0                  base-sys-shlib
 ./usr/lib/libbz2.so.1.0                                base-sys-shlib
-./usr/lib/libc.so.12.135                       base-sys-shlib
+./usr/lib/libc.so.12.136                       base-sys-shlib
 ./usr/lib/libcdk.so.1.0                                base-sys-shlib
 ./usr/lib/libcom_err.so.4.1                    base-krb5-shlib         kerberos
 ./usr/lib/libcrypt.so.0.2                      base-sys-shlib
diff -r 086240e1bd65 -r 6bf2d83ec682 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Fri Dec 30 16:12:11 2005 +0000
+++ b/distrib/sets/lists/comp/mi        Fri Dec 30 23:07:31 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.839 2005/12/29 14:53:45 tsutsui Exp $
+#      $NetBSD: mi,v 1.840 2005/12/30 23:07:32 agc Exp $
 ./etc/mtree/set.comp                           comp-sys-root
 ./usr/bin/addr2line                            comp-debug-bin          bfd
 ./usr/bin/ar                                   comp-util-bin           bfd
@@ -519,6 +519,7 @@
 ./usr/include/fstab.h                          comp-c-include
 ./usr/include/fs/sysvbfs/bfs.h                 comp-c-include
 ./usr/include/fts.h                            comp-c-include
+./usr/include/ftw.h                            comp-c-include
 ./usr/include/g++/ACG.h                                comp-obsolete           obsolete
 ./usr/include/g++/AllocRing.h                  comp-obsolete           obsolete
 ./usr/include/g++/Binomial.h                   comp-obsolete           obsolete
@@ -3173,6 +3174,7 @@
 ./usr/share/man/cat3/ftok.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/ftrylockfile.0            comp-c-catman           .cat
 ./usr/share/man/cat3/fts.0                     comp-c-catman           .cat
+./usr/share/man/cat3/ftw.0                     comp-c-catman           .cat
 ./usr/share/man/cat3/fts_children.0            comp-c-catman           .cat
 ./usr/share/man/cat3/fts_close.0               comp-c-catman           .cat
 ./usr/share/man/cat3/fts_open.0                        comp-c-catman           .cat
@@ -3934,6 +3936,7 @@
 ./usr/share/man/cat3/newwin.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/nextafter.0               comp-c-catman           .cat
 ./usr/share/man/cat3/nextafterf.0              comp-c-catman           .cat
+./usr/share/man/cat3/nftw.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/ngettext.0                        comp-c-catman           .cat
 ./usr/share/man/cat3/nice.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/nl.0                      comp-c-catman           .cat
@@ -7110,6 +7113,7 @@
 ./usr/share/man/man3/ftok.3                    comp-c-man              .man
 ./usr/share/man/man3/ftrylockfile.3            comp-c-man              .man
 ./usr/share/man/man3/fts.3                     comp-c-man              .man
+./usr/share/man/man3/ftw.3                     comp-c-man              .man
 ./usr/share/man/man3/fts_children.3            comp-c-man              .man
 ./usr/share/man/man3/fts_close.3               comp-c-man              .man
 ./usr/share/man/man3/fts_open.3                        comp-c-man              .man
@@ -7871,6 +7875,7 @@
 ./usr/share/man/man3/newwin.3                  comp-c-man              .man
 ./usr/share/man/man3/nextafter.3               comp-c-man              .man
 ./usr/share/man/man3/nextafterf.3              comp-c-man              .man
+./usr/share/man/man3/nftw.3                    comp-c-man              .man
 ./usr/share/man/man3/ngettext.3                        comp-c-man              .man
 ./usr/share/man/man3/nice.3                    comp-c-man              .man
 ./usr/share/man/man3/nl.3                      comp-c-man              .man
diff -r 086240e1bd65 -r 6bf2d83ec682 include/Makefile
--- a/include/Makefile  Fri Dec 30 16:12:11 2005 +0000
+++ b/include/Makefile  Fri Dec 30 23:07:31 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.120 2005/04/03 20:09:29 christos Exp $
+#      $NetBSD: Makefile,v 1.121 2005/12/30 23:07:33 agc Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/4/94
 
 # Doing a make includes builds /usr/include
@@ -9,7 +9,7 @@
 
 INCS=  a.out.h ar.h assert.h bitstring.h bm.h cpio.h ctype.h db.h dirent.h \
        disktab.h dlfcn.h err.h errno.h fmtmsg.h fnmatch.h fstab.h fts.h \
-       getopt.h glob.h grp.h ifaddrs.h iconv.h \
+       ftw.h getopt.h glob.h grp.h ifaddrs.h iconv.h \
        inttypes.h iso646.h kvm.h langinfo.h libgen.h \
        limits.h link.h link_aout.h link_elf.h locale.h \
        login_cap.h lwp.h malloc.h math.h md2.h \
diff -r 086240e1bd65 -r 6bf2d83ec682 include/ftw.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/ftw.h     Fri Dec 30 23:07:31 2005 +0000
@@ -0,0 +1,62 @@
+/* $NetBSD: ftw.h,v 1.1 2005/12/30 23:07:33 agc Exp $ */
+
+/*     From OpenBSD: ftw.h,v 1.1 2003/07/21 21:13:18 millert Exp       */
+
+/*
+ * Copyright (c) 2003 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#ifndef        _FTW_H
+#define        _FTW_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*
+ * Valid flags for the 3rd argument to the function that is passed as the
+ * second argument to ftw(3) and nftw(3).  Say it three times fast!
+ */
+#define        FTW_F           0       /* File.  */
+#define        FTW_D           1       /* Directory.  */
+#define        FTW_DNR         2       /* Directory without read permission.  */
+#define        FTW_DP          3       /* Directory with subdirectories visited.  */
+#define        FTW_NS          4       /* Unknown type; stat() failed.  */
+#define        FTW_SL          5       /* Symbolic link.  */
+#define        FTW_SLN         6       /* Sym link that names a nonexistent file.  */
+
+/*
+ * Flags for use as the 4th argument to nftw(3).  These may be ORed together.
+ */
+#define        FTW_PHYS        0x01    /* Physical walk, don't follow sym links.  */
+#define        FTW_MOUNT       0x02    /* The walk does not cross a mount point.  */
+#define        FTW_DEPTH       0x04    /* Subdirs visited before the dir itself. */
+#define        FTW_CHDIR       0x08    /* Change to a directory before reading it. */
+
+struct FTW {
+       int base;
+       int level;
+};
+
+__BEGIN_DECLS
+int    ftw(const char *, int (*)(const char *, const struct stat *, int), int);
+int    nftw(const char *, int (*)(const char *, const struct stat *, int,
+           struct FTW *), int, int);
+__END_DECLS
+
+#endif /* !_FTW_H */
diff -r 086240e1bd65 -r 6bf2d83ec682 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Fri Dec 30 16:12:11 2005 +0000
+++ b/lib/libc/gen/Makefile.inc Fri Dec 30 23:07:31 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.147 2005/10/03 14:56:32 wiz Exp $
+#      $NetBSD: Makefile.inc,v 1.148 2005/12/30 23:07:32 agc Exp $
 #      from: @(#)Makefile.inc  8.6 (Berkeley) 5/4/95
 
 # gen sources
@@ -9,14 +9,15 @@
        devname.c dirname.c disklabel.c err.c errx.c errlist.c \
        errno.c execl.c execle.c execlp.c execv.c execvp.c extattr.c \
        fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \
-       fts.c getbsize.c getcap.c getcwd.c \
+       fts.c ftw.c getbsize.c getcap.c getcwd.c \
        getdevmajor.c getdomainname.c getgrent.c \
        getgrouplist.c getgroupmembership.c gethostname.c \
        getloadavg.c getlogin.c getmntinfo.c \
        getnetgrent.c getpagesize.c \
        getpass.c getprogname.c getpwent.c getttyent.c \
        getusershell.c glob.c humanize_number.c initgroups.c \
-       isascii.c isatty.c isctype.c lockf.c nice.c nlist.c nlist_aout.c \
+       isascii.c isatty.c isctype.c lockf.c nftw.c \
+       nice.c nlist.c nlist_aout.c \
        nlist_coff.c nlist_ecoff.c nlist_elf32.c nlist_elf64.c opendir.c \
        pause.c popen.c psignal.c pthread_atfork.c pwcache.c \
        pw_scan.c raise.c randomid.c readdir.c rewinddir.c \
@@ -47,7 +48,7 @@
        ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 \
        endutxent.3 err.3 exec.3 extattr.3 \
        fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 fpgetmask.3 frexp.3 \
-       ftok.3 fts.3 \
+       ftok.3 fts.3 ftw.3 \
        getbsize.3 cgetcap.3 getcwd.3 getdevmajor.3 \
        getdomainname.3 getdiskbyname.3 getfsent.3 \
        getgrent.3 getgrouplist.3 gethostname.3 getlastlogx.3 getloadavg.3 \
@@ -86,6 +87,7 @@
        fpgetmask.3 fpsetsticky.3
 MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \
        fts.3 fts_set.3 fts.3 fts_close.3
+MLINKS+=ftw.3 nftw.3
 MLINKS+=cgetcap.3 cgetclose.3 cgetcap.3 cgetent.3 \
        cgetcap.3 cgetfirst.3 cgetcap.3 cgetmatch.3 cgetcap.3 cgetnext.3 \
        cgetcap.3 cgetnum.3 cgetcap.3 cgetset.3 cgetcap.3 cgetstr.3 \
diff -r 086240e1bd65 -r 6bf2d83ec682 lib/libc/gen/ftw.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/ftw.3        Fri Dec 30 23:07:31 2005 +0000
@@ -0,0 +1,211 @@
+.\"    $NetBSD: ftw.3,v 1.1 2005/12/30 23:07:32 agc Exp $
+.\"
+.\"    From OpenBSD: ftw.3,v 1.4 2003/10/30 18:52:58 jmc Exp
+.\"
+.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\" Sponsored in part by the Defense Advanced Research Projects
+.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
+.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
+.\"
+.Dd May 20, 2003
+.Dt FTW 3
+.Os
+.Sh NAME
+.Nm ftw, nftw
+.Nd traverse (walk) a file tree
+.Sh SYNOPSIS
+.Fd #include <ftw.h>
+.Ft int
+.Fo ftw
+.Fa "const char *path"
+.Fa "int (*fn)(const char *, const struct stat *, int)"
+.Fa "int maxfds"
+.Fc
+.Ft int
+.Fo nftw
+.Fa "const char *path"
+.Fa "int (*fn)(const\ char\ *, const\ struct\ stat\ *, int, struct\ FTW\ *)"
+.Fa "int maxfds"
+.Fa "int flags"
+.Fc
+.Sh DESCRIPTION
+.Bf -symbolic
+These functions are provided for compatibility with legacy code.
+New code should use the
+.Xr fts 3
+functions.
+.Ef
+.Pp
+The
+.Fn ftw
+and
+.Fn nftw
+functions traverse (walk) the directory hierarchy rooted in
+.Fa path .
+For each object in the hierarchy, these functions call the function
+pointed to by
+.Fa fn .
+The
+.Fn ftw
+function passes this function a pointer to a NUL-terminated string containing
+the name of the object, a pointer to a stat structure corresponding to the
+object, and an integer flag.
+The
+.Fn nftw
+function passes the aforementioned arguments plus a pointer to a
+.Dv FTW
+structure as defined by
+.Aq Pa ftw.h
+(shown below):
+.Bd -literal
+struct FTW {
+    int base;  /* offset of basename into pathname */
+    int level; /* directory depth relative to starting point */
+};
+.Ed
+.Pp
+Possible values for the flag passed to
+.Fa fn
+are:
+.Bl -tag -width FTW_DNR
+.It Dv FTW_F
+A regular file.
+.It Dv FTW_D
+A directory being visited in pre-order.
+.It Dv FTW_DNR
+A directory which cannot be read.
+The directory will not be descended into.
+.It Dv FTW_DP
+A directory being visited in post-order
+.No ( Ns Fn nftw
+only).
+.It Dv FTW_NS
+A file for which no
+.Xr stat 2
+information was available.



Home | Main Index | Thread Index | Old Index