Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Feb 2005 11:56:50 -0500
From:      Louis LeBlanc <FreeBSD@keyslapper.net>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Cc:        Ruben de Groot <mail25@bzerk.org>
Subject:   Re: library call for directory path creation?
Message-ID:  <20050202165650.GB77499@keyslapper.net>
In-Reply-To: <20050202152307.GA62361@ei.bzerk.org>
References:  <20050201193507.GD71726@keyslapper.net> <200502011258.59704.reso3w83@verizon.net> <20050201213920.GE71726@keyslapper.net> <20050202152307.GA62361@ei.bzerk.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline

On 02/02/05 04:23 PM, Ruben de Groot sat at the `puter and typed:
> On Tue, Feb 01, 2005 at 04:39:21PM -0500, Louis LeBlanc typed:
> > On 02/01/05 12:58 PM, Michael C. Shultz sat at the `puter and typed:
> > > On Tuesday 01 February 2005 11:35 am, Louis LeBlanc wrote:
> > > > I know there might be a better place for this question, but here
> > > > goes.
> > > >
> > > > I'm working on a utility that has to, among many other things, create
> > > > directory paths, often with a series of parent directories that may
> > > > not already exist.  Solaris has mkdirp(3GEN) in the libgen library,
> > > > but I can't find a library call that will do this in FreeBSD.  Kind
> > > > of like `mkdir -p` would.
> > > >
> > > > I know it would be pretty trivial to roll my own, and if I can't find
> > > > it I will.  I'm just curious if anyone knows of an *existing* library
> > > > call that would do this.
> > > >
> > > > TIA
> > > > Lou
> > > 
> > > Assuming your working in C what is wrong with:
> > > 
> > > char command[]	= "mkdir -p /path/to/whatever";
> > > 
> > > system( command );
> > 
> > Nothing, except that calling a system command from C when you can roll
> > your own method in about 18 lines of code is usually not ideal.
> > Particularly when speed is important.  And yes, it is definitely
> > important - disk access can be an insurmountable bottleneck for high
> > volume systems if it is neglected at the implemenation stage.
> > 
> > I only wanted a system lib call because I trust FreeBSDs implementation
> > to be faster than my quick throw together.
> > 
> > I've already written it.  It's not pretty, and probably not as fast as a
> > system lib would be (it has to make 1 system call per directory in the
> > path, rather than just one system call for the whole path).  It is,
> > however, much faster than a call to system() would be.
> 
> Actually, the mkdirp(3GEN) library routine in Solaris probably makes the
> same amount of system calls as your implementation:
> 
> > uname -sr
> SunOS 5.9
> > cat mkdirp.c
> #include <libgen.h>
> #include <sys/stat.h>
> 
> #define path "/tmp/a/b/c/d"
> 
> int main(void) {
>         mkdirp(path,S_IRWXU);
> }
> 
> > gcc -lgen -o mkdirp mkdirp.c
> > truss ./mkdirp |& tail -10
> mkdir("/tmp/a/b/c/d", 0700)                     Err#2 ENOENT
> access("/tmp/a/b/c", 0)                         Err#2 ENOENT
> access("/tmp/a/b", 0)                           Err#2 ENOENT
> access("/tmp/a", 0)                             Err#2 ENOENT
> access("/tmp", 0)                               = 0
> mkdir("/tmp/a", 0700)                           = 0
> mkdir("/tmp/a/b", 0700)                         = 0
> mkdir("/tmp/a/b/c", 0700)                       = 0
> mkdir("/tmp/a/b/c/d", 0700)                     = 0
> _exit(-13163152)


I shoulda thought of that.

This gives me another idea to consider for my implementation too.

Thanks!

Lou
-- 
Louis LeBlanc                          FreeBSD-at-keyslapper-DOT-net
Fully Funded Hobbyist,                   KeySlapper Extrordinaire :)
This is a list only address, and the return address is a black hole!
Send off-list email to:                leblanc at keyslapper d.t net
Key fingerprint = C5E7 4762 F071 CE3B ED51  4FB8 AF85 A2FE 80C8 D9A2

court, n.:
  A place where they dispense with justice.
    -- Arthur Train

--4Ckj6UjgE2iN1+kY
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)

iD8DBQFCAQZRr4Wi/oDI2aIRAoCdAJkBpw4PbBl8rd+ZGjjXaWeL90HfQwCfciXO
+YpbZdqLz5otd3Qs6Z7jOUM=
=Wmys
-----END PGP SIGNATURE-----

--4Ckj6UjgE2iN1+kY--



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