Tom Ridge
2014-06-16 09:49:13 UTC
Dear List,
Reading the spec for open, it appears that the intention is that open
with O_CREAT cannot be used to create directories. The reasoning is
that a command such as:
open /a/b [O_CREAT]
would ordinarily create a non-directory file b in directory a. In
order to create a directory, one might try:
open /a/b/ [O_CREAT]
but this would fail if b does not exist. Can someone confirm that open
cannot be used to create directories?
Another question: if b does exist, then open /a/b/ [O_CREAT] may fail
with ENOTDIR. The clause from the spec is:
[ENOENT] or [ENOTDIR]
O_CREAT is set, and the path argument contains at least one non-
<slash> character and ends with one or more trailing <slash>
characters. If path names an existing file, an [ENOENT] error shall
not occur.
But the error ENOTDIR seems confusing. The problem here seems to be
that the target /a/b/ IS a directory, and that this is not allowed in
combination with the flag O_CREAT. Is there a reason not to allow
EISDIR, or perhaps EINVAL, in this situation?
Thanks
Reading the spec for open, it appears that the intention is that open
with O_CREAT cannot be used to create directories. The reasoning is
that a command such as:
open /a/b [O_CREAT]
would ordinarily create a non-directory file b in directory a. In
order to create a directory, one might try:
open /a/b/ [O_CREAT]
but this would fail if b does not exist. Can someone confirm that open
cannot be used to create directories?
Another question: if b does exist, then open /a/b/ [O_CREAT] may fail
with ENOTDIR. The clause from the spec is:
[ENOENT] or [ENOTDIR]
O_CREAT is set, and the path argument contains at least one non-
<slash> character and ends with one or more trailing <slash>
characters. If path names an existing file, an [ENOENT] error shall
not occur.
But the error ENOTDIR seems confusing. The problem here seems to be
that the target /a/b/ IS a directory, and that this is not allowed in
combination with the flag O_CREAT. Is there a reason not to allow
EISDIR, or perhaps EINVAL, in this situation?
Thanks