[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: truncate-fail-diag failure on Solaris
From: |
Bruno Haible |
Subject: |
Re: truncate-fail-diag failure on Solaris |
Date: |
Thu, 12 Jun 2008 13:47:56 +0200 |
User-agent: |
KMail/1.5.4 |
Jim Meyering wrote:
> It's worth noting in documentation that with the replacement function,
> opening-for-write any name ending with a slash (regardless of
> whether the non-trailing-slashed name exists) will always fail.
IMO that's already clear from POSIX [1], which says:
"A pathname that contains at least one non-slash character and that ends with
one or more trailing slashes shall be resolved as if a single dot character
( '.' ) were appended to the pathname."
"The special filename dot shall refer to the directory specified by its
predecessor."
... and therefore does not need extra documentation.
> Isn't it the case that on some older systems, that opening a directory
> for write access could succeed, but only the actual write would fail?
This use of open() is already forbidden by POSIX [2]:
"The open() function shall fail if:
...
[EISDIR]
The named file is a directory and oflag includes O_WRONLY or O_RDWR."
But I can certainly add a comment in the code...
Bruno
[1] http://www.opengroup.org/susv3/basedefs/xbd_chap04.html
[2] http://www.opengroup.org/susv3/functions/open.html
*** lib/open.c.orig 2008-06-12 13:46:54.000000000 +0200
--- lib/open.c 2008-06-12 13:45:45.000000000 +0200
***************
*** 53,58 ****
--- 53,79 ----
}
# if OPEN_TRAILING_SLASH_BUG
+ /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
+ is specified, then fail.
+ Rationale: POSIX
<http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+ says that
+ "A pathname that contains at least one non-slash character and that
+ ends withone or more trailing slashes shall be resolved as if a
+ single dot character ( '.' ) were appended to the pathname."
+ and
+ "The special filename dot shall refer to the directory specified by
+ its predecessor."
+ If the named file already exists as a directory, then
+ - if O_CREAT is specified, open() must fail because of the semantics
+ of O_CREAT,
+ - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
+ <http://www.opengroup.org/susv3/functions/open.html> says that it
+ fails with errno = EISDIR in this case.
+ If the named file does not exist or does not name a directory, then
+ - if O_CREAT is specified, open() must fail since open() cannot create
+ directories,
+ - if O_WRONLY or O_RDWR is specified, open() must fail because the
+ file does not contain a '.' directory. */
if (flags & (O_CREAT | O_WRONLY | O_RDWR))
{
size_t len = strlen (filename);