[PATCH] reimplement dirname v2

Matthias Andree mandree at FreeBSD.org
Fri Sep 9 16:51:54 UTC 2011


Am 08.09.2011 22:24, schrieb Tito:
> On Thursday 08 September 2011 18:11:22 Matthias Andree wrote:
>> If libc has a good dirname() implementation it should be used. Please
>> make that configurable and have it default to off on (e)glibc and FreeBSD.
> 
> Hi,
> not that I think that this will ever be checked in,
> nonetheless it would be interesting to know
> what exactly a good dirname implementation is :-)

Let's start with 'POSIX conforming'. :)

> I think that the rationale for an eventual checkin
> of this code is that due to the fact that there are 
> different implementations in different libcs
> and even in the same libc, we want to stick with
> one that works everywhere independently
> of the libc used.

busybox need not patch up b0rked libc implementations.

> I wonder also how the FreeBSD dirname
> plays with busybox code like this in install.c:

Nicely, but...

> 			if (opts & OPT_MKDIR_LEADING) {
> 				char *ddir = xstrdup(dest);
> 				bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
> 				/* errors are not checked. copy_file
> 				 * will fail if dir is not created. */
> 				free(ddir);
> 			}

...these xstrdup()/free() hoops aren't necessary on FreeBSD because it
leaves the string its argument points to alone.

> Wouldn't this leak memory with the freebsd dirname?

Somewhat. It allocates a static buffer of MAXPATHLEN bytes on first use
and reuses it on subsequent calls (trashing the former contents), and
that gets reclaimed once the application exits.


More information about the busybox mailing list