Skip to content

Commit a7439d0

Browse files
rscharfegitster
authored andcommitted
xopen: explicitly report creation failures
If the flags O_CREAT and O_EXCL are both given then open(2) is supposed to create the file and error out if it already exists. The error message in that case looks like this: fatal: could not open 'foo' for writing: File exists Without further context this is confusing: Why should the existence of the file pose a problem? Isn't that a requirement for writing to it? Add a more specific error message for that case to tell the user that we actually don't expect the file to preexist, so the example becomes: fatal: unable to create 'foo': File exists Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit a7439d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

wrapper.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ int xopen(const char *path, int oflag, ...)
193193
if (errno == EINTR)
194194
continue;
195195

196-
if ((oflag & O_RDWR) == O_RDWR)
196+
if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
197+
die_errno(_("unable to create '%s'"), path);
198+
else if ((oflag & O_RDWR) == O_RDWR)
197199
die_errno(_("could not open '%s' for reading and writing"), path);
198200
else if ((oflag & O_WRONLY) == O_WRONLY)
199201
die_errno(_("could not open '%s' for writing"), path);

0 commit comments

Comments
 (0)