*BSD News Article 55022


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.sprintlink.net!howland.reston.ans.net!nntp.crl.com!crl.crl.com!not-for-mail
From: ggrant@crl.com (Gary E. Grant)
Newsgroups: comp.unix.misc,comp.unix.bsd.freebsd.misc
Subject: Re: equivalent of ftw
Date: 16 Nov 1995 12:21:02 -0800
Organization: This old house in montreal
Lines: 68
Message-ID: <48g6fe$1pt@crl.crl.com>
References: <48fvbg$ava@jupiter.planet.net>
NNTP-Posting-Host: crl.com
Keywords: unix, ftw, C lib
Xref: euryale.cc.adfa.oz.au comp.unix.misc:19513 comp.unix.bsd.freebsd.misc:8997

In article <48fvbg$ava@jupiter.planet.net>,
HCLA  Deepak Goel <hcla@earth.planet.net> wrote:
>Hi,
>
>I am porting an application to NextStep OS.
>This application uses ftw C library call at many
>places and it is not available with NextStep OS.
>
>Is there any known equivalent to ftw?  
>Is there any public domain library which includes
>this function?
Why don't you just 'roll your own ' FTW() ?
Shouldnt take more than 10-20 minutes to write it in C/C++.
FTW is a simple tree (traversal) routine. Else go to the
FREEBSD sources for the system call ftw() and use that code 
on the NextStep o/s.

Gary :-)

=====================================


DESCRIPTION
     ftw() recursively descends the directory hierarchy rooted in
     path.   For  each  object  in the hierarchy, ftw() calls fn,
     passing it a pointer to a null-terminated  character  string
     containing  the  name  of  the object, a pointer to a stat()
     structure (see stat(2V)) containing  information  about  the
     object,  and  an  integer.   Possible values of the integer,
     defined in the <ftw.h> header file, are FTW_F  for  a  file,
     FTW_D  for  a directory, FTW_DNR for a directory that cannot
     be read, and FTW_NS for an object for which stat() could not
     successfully  be  executed.  If the integer is FTW_DNR, des-
     cendants of that directory will not be  processed.   If  the
     integer  is  FTW_NS,  the stat() structure will contain gar-
     bage.  An example of an object that would cause FTW_NS to be
     passed  to  fn  would be a file in a directory with read but
     without execute (search) permission.

     ftw() visits a directory before visiting any of its  descen-
     dants.

     The tree traversal continues until the tree is exhausted, an
     invocation  of  fn returns a nonzero value, or some error is
     detected within ftw() (such as an I/O error).  If  the  tree
     is  exhausted,  ftw() returns zero.  If fn returns a nonzero
     value, ftw() stops its tree traversal and  returns  whatever
     value  was  returned  by  fn.  If ftw() detects an error, it
     returns -1, and sets the error type in errno.

     ftw() uses one file descriptor for each level in  the  tree.
     The  depth argument limits the number of file descriptors so
     used.  If depth is zero or negative, the effect is the  same
     as  if it were 1.  depth must not be greater than the number
     of file descriptors currently available for use.  ftw() will
     run more quickly if depth is at least as large as the number
     of levels in the tree.

SEE ALSO
     stat(2V), malloc(3V)

BUGS
     Because ftw()  is  recursive,  it  is  possible  for  it  to

Sun Release 4.1   Last change: 22 November 1987                 1