Subject: Re: mkdir() and trailing "/"s
To: None <hwr@pilhuhn.de>
From: Giles Lean <giles@nemeton.com.au>
List: current-users
Date: 10/09/1999 23:07:35
On 9 Oct 1999 12:12:40 GMT  Heiko W.Rupp wrote:
> Mark Davies wrote:
> |and this fails on NetBSD.  A quick test has confirmed that the mkdir() with
> |trailing slash works on Solaris and Digital UNIX and I presume it works on 
> |Linux (or some KDE user would have noticed by now) so should it be made to 
> |work for *BSD  (following the be liberal in what you accept principle)?
> 
> There is already a PR open on this (PR 8155).
> 
> What does Posix say?

It doesn't, really.  The closest thing I can find in UNIX98
(influenced by POSIX ... my POSIX standard is still "in the mail")
says:

 pathname

    A character string that is used to identify a file. A pathname
    consists of, at most, {PATH_MAX} bytes, including the terminating
    null byte. It has an optional beginning slash, followed by zero or
    more filenames separated by slashes. If the pathname refers to a
    directory, it may also have one or more trailing slashes. Multiple
    successive slashes are considered to be the same as one slash. A
    pathname that begins with two successive slashes may be
    interpreted in an implementation-dependent manner, although more
    than two leading slashes are treated as a single slash. The
    interpretation of the pathname is described in pathname
    resolution.

Since the argument to mkdir(2) is a pathname that refers to a
directory it is arguable that the trailing slash is allowable, however
there is considerable prior art ("BSD") that doesn't allow such a
trailing slash.

I would prefer to see a trailing slash allowed in mkdir(2) -- there
are few instances where the performance of mkdir is going to matter,
and a reasonable implementation will only check if it fails so
portable code that doesn't use a trailing slash should not be
impacted.

How about someone offers a patch?  I'd be tempted to look into this
but since I work with non-free Unix source I might be "mentally
contaminated" and NetBSD doesn't need that sort of problem  ...

Regards,

Giles