open.c (le-1.16.7) | : | open.c (le-1.16.8) | ||
---|---|---|---|---|
/* Open a descriptor to a file. | /* Open a descriptor to a file. | |||
Copyright (C) 2007-2019 Free Software Foundation, Inc. | Copyright (C) 2007-2021 Free Software Foundation, Inc. | |||
This program is free software: you can redistribute it and/or modify | This program is free software: you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 3 of the License, or | the Free Software Foundation; either version 3 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
skipping to change at line 33 | skipping to change at line 33 | |||
#include <config.h> | #include <config.h> | |||
/* Get the original definition of open. It might be defined as a macro. */ | /* Get the original definition of open. It might be defined as a macro. */ | |||
#include <fcntl.h> | #include <fcntl.h> | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#undef __need_system_fcntl_h | #undef __need_system_fcntl_h | |||
static int | static int | |||
orig_open (const char *filename, int flags, mode_t mode) | orig_open (const char *filename, int flags, mode_t mode) | |||
{ | { | |||
#if defined _WIN32 && !defined __CYGWIN__ | ||||
return _open (filename, flags, mode); | ||||
#else | ||||
return open (filename, flags, mode); | return open (filename, flags, mode); | |||
#endif | ||||
} | } | |||
/* Specification. */ | /* Specification. */ | |||
/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates | /* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates | |||
this include because of the preliminary #include <fcntl.h> above. */ | this include because of the preliminary #include <fcntl.h> above. */ | |||
#include "fcntl.h" | #include "fcntl.h" | |||
#include "cloexec.h" | #include "cloexec.h" | |||
#include <errno.h> | #include <errno.h> | |||
skipping to change at line 113 | skipping to change at line 117 | |||
- if O_CREAT is specified, open() must fail because of the semantics | - if O_CREAT is specified, open() must fail because of the semantics | |||
of O_CREAT, | of O_CREAT, | |||
- if O_WRONLY or O_RDWR is specified, open() must fail because POSIX | - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX | |||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html> | <https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html> | |||
says that it fails with errno = EISDIR in this case. | 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 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 | - if O_CREAT is specified, open() must fail since open() cannot create | |||
directories, | directories, | |||
- if O_WRONLY or O_RDWR is specified, open() must fail because the | - if O_WRONLY or O_RDWR is specified, open() must fail because the | |||
file does not contain a '.' directory. */ | file does not contain a '.' directory. */ | |||
if (flags & (O_CREAT | O_WRONLY | O_RDWR)) | if ((flags & O_CREAT) | |||
|| (flags & O_ACCMODE) == O_RDWR | ||||
|| (flags & O_ACCMODE) == O_WRONLY) | ||||
{ | { | |||
size_t len = strlen (filename); | size_t len = strlen (filename); | |||
if (len > 0 && filename[len - 1] == '/') | if (len > 0 && filename[len - 1] == '/') | |||
{ | { | |||
errno = EISDIR; | errno = EISDIR; | |||
return -1; | return -1; | |||
} | } | |||
} | } | |||
#endif | #endif | |||
fd = orig_open (filename, | fd = orig_open (filename, | |||
flags & ~(have_cloexec <= 0 ? O_CLOEXEC : 0), mode); | flags & ~(have_cloexec < 0 ? O_CLOEXEC : 0), mode); | |||
if (flags & O_CLOEXEC) | if (flags & O_CLOEXEC) | |||
{ | { | |||
if (! have_cloexec) | if (! have_cloexec) | |||
{ | { | |||
if (0 <= fd) | if (0 <= fd) | |||
have_cloexec = 1; | have_cloexec = 1; | |||
else if (errno == EINVAL) | else if (errno == EINVAL) | |||
{ | { | |||
fd = orig_open (filename, flags & ~O_CLOEXEC, mode); | fd = orig_open (filename, flags & ~O_CLOEXEC, mode); | |||
End of changes. 5 change blocks. | ||||
3 lines changed or deleted | 9 lines changed or added |