Version française
Home     About     Download     Resources     Contact us    
Browse thread
Bug in Filename.basename?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Bug in Filename.basename?
Zitat von Erik de Castro Lopo <mle+ocaml@mega-nerd.com>:

> Richard Jones wrote:
>
> > I think the OCaml one is what I'd reasonably expect actually.
> >
> > The GNU documentation for basename says:
> >
> >   `basename' removes any leading directory components from NAME.
> >
> > and a/b/c/ are leading directory components.
>
> The word "leading" in the above is at best, ambiguous.
>
> Regardless of what the documentation says, the behaviour of Ocaml's
> basename function is different from the basename program (from the
> GNU coreutils package) on my Linux system.
[...]

But possibly it's not different to other basename-implementations.

Do you think *your* current basename should be the way, all other people
should go, when implementing a function that has the same name and a similar
functionality?
What, if your basename-implemantation is buggy? Should all
other people rewrite a buggy thing?



>
> Since I suspect that the basename function is meant to emulate the
> basename program I see the Ocaml function's behaviour as a bug. I
> would however discount this if the behaviour of basename on some
> other commonly used system (eg *BSD) matched the Ocaml behaviour.
>
> However, here is a comparison chart of what I have tested so far:
>
>                                  "a/b/c"     "a/b/c/"
>     Linux basename                 "c"         "c"
>     Mac OSX basename               "c"         "c"
>     Ocaml Filename.basename        "c"         "."
[...]

It doesn't matter.

It even doesn't matter that Filename.basename might be correct,
when loohing at the basename-documentation.

You (both) have to look in the OCaml-documentation,
if you think it might be buggy.

When you look there, you find this:
======================================================================
val basename : string -> string

Split a file name into directory name / base file name. concat (dirname name)
(basename name) returns a file name which is equivalent to name. Moreover,
after setting the current directory to dirname name (with Sys.chdir),
references to basename name (which is a relative file name) designate the same
file as name before the call to Sys.chdir.

The result is not specified if the argument is not a valid file name (for
example, under Unix if there is a NUL character in the string).

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

Looking at that documentation, I can't see no bug in the implementation.


When you want to know how your car's GPS-navigation system works,
do you look in the documentation of your video-camera or vacuum-cleaner?
And if you then drive in the wrong direction, who do you will blame for that?


Ciao,
   Oliver