Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2007 09:52:13 -0400
From:      Mike Meyer <mwm-keyword-freebsdhackers2.e313df@mired.org>
To:        Garrett Cooper <youshi10@u.washington.edu>
Cc:        Alexander Leidinger <Alexander@Leidinger.net>, hackers@freebsd.org
Subject:   Re: Using shell commands versus C equivalents
Message-ID:  <18031.63117.423936.99266@bhuda.mired.org>
In-Reply-To: <466F9020.9050306@u.washington.edu>
References:  <466F86C6.7010006@u.washington.edu> <20070613083046.atl5dyq3s488s0o8@webmail.leidinger.net> <466F9020.9050306@u.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
In <466F9020.9050306@u.washington.edu>, Garrett Cooper <youshi10@u.washington.edu> typed:
> Alexander Leidinger wrote:
> > Quoting Garrett Cooper <youshi10@u.washington.edu> (from Tue, 12 Jun 
> > 2007 22:55:18 -0700):
> >
> >> Another simple question (I hope):
> >>    Is there any reason why shell commands should be used in place of a
> >> C command (in this case chmod via vsystem instead of the chmod(2)
> >> function)? It seems like the fork / exec would be more expensive with
> >> the shell command, but any area where code could be optimized is more
> >> than welcome I would think.
> >
> > If it is just one file, I don't see the reason to use the shell 
> > command, but if you need to reinvent "chmod -R", I don't see a reason 
> > to forbid the use of the shell command (pragmatic programming).
> >
> > Bye,
> > Alexander.
> >
>     Exactly my thinking (ch{own,mod} for one file, not reinventing the 
> -R 'wheel'). After looking over style(7) I don't see anything about not 
> doing that.

While I agree in principal - if chmod already implements some
hard-to-implement functionality, then using it only makes sense - I
don't think -R qualifies. It's implemented via the fts library, which
makes recursing through a directory tree about as difficult as
scanning a directory. In fact, fts has features that dir* doesn't, so
there are instances where fts is preferable to the dir* routines for
scanning a directory.

	<mike
-- 
Mike Meyer <mwm@mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?18031.63117.423936.99266>