Hi Eric, hi Paul,

I appreciate your quick and competent answers !

Am Dienstag, 23. Dezember 2014, 10:07:13 schrieb Eric Blake:
> On 12/23/2014 09:53 AM, Tim Rühsen wrote:
> > Hi,
> > 
> > I want to avoid the basename() POSIX/GNU incompatibility and also would
> > like to have basename() working on Windows (it is a user requesting this
> > for Wget).
> You don't want basename() and dirname() (the POSIX rules on those
> functions mean that they cannot work for Windows drive letters).  You
> WANT to use base_name() and dir_name().
> 
> > I see the gnulib module 'dirname' contains the base_name() function.
> 
> base_name() returns a malloc'd string that contains the basename of the
> input string.  You can also use last_component() to get a pointer to the
> basename within the input string rather than a malloc'd copy (the
> semantics are slightly different since base_name() malloc's "." for the
> empty string while last_component() cannot).  And just as
> last_component() can be used to avoid xalloc() so that a library doesn't
> die on allocation failures, so can mdir_name() avoid xalloc in place of
> dir_name().
> 
> > But I can't find any documentation for it.
> 
> Where would you suggest such documentation beyond what is already in
> lib/{base,dir}name{,-lgpl}.c?

As Paul said, what I found when searching the internet was from here
doc/posix-functions/basename.texi
And that just mentions base_name() and is not a documentation.
I wasn't sure how 'official' the comments in the source code are.

> /* Return the address of the last file name component of NAME.  If
>    NAME has no relative file name components because it is a file
>    system root, return the empty string.  */
> char *
> last_component (char const *name)

Very good to know about this.


> They are stable.  Use them.

That's what I am going to do ;-)

Regards, Tim

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to