/* Low-level file-handling.
- Copyright (C) 2012, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2012-2014 Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifdef GDBSERVER
-#include "server.h"
-#else
-#include "defs.h"
-#include "gdb_string.h"
-#endif
+#include "common-defs.h"
#include "filestuff.h"
#include "gdb_vecs.h"
-
-#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
-#include "gdb_stat.h"
+#include <sys/stat.h>
#ifdef USE_WIN32API
#include <winsock2.h>
#ifndef HAVE_FDWALK
-#include "gdb_dirent.h"
+#include <dirent.h>
/* Replacement for fdwalk, if the system doesn't define it. Walks all
open file descriptors (though this implementation may walk closed
{
int max, fd;
-#ifdef HAVE_GETRLIMIT
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
struct rlimit rlim;
if (getrlimit (RLIMIT_NOFILE, &rlim) == 0 && rlim.rlim_max != RLIM_INFINITY)
don't use a hashtab because libiberty isn't linked into gdbserver;
and anyway we don't expect there to be many open fds. */
-DEF_VEC_I (int);
-
static VEC (int) *open_fds;
/* An fdwalk callback function used by notice_open_fds. It puts the
FILE *
gdb_fopen_cloexec (const char *filename, const char *opentype)
{
- FILE *result = NULL;
- static int fopen_e_ever_failed;
-
- if (!fopen_e_ever_failed)
+ FILE *result;
+ /* Probe for "e" support once. But, if we can tell the operating
+ system doesn't know about close on exec mode "e" without probing,
+ skip it. E.g., the Windows runtime issues an "Invalid parameter
+ passed to C runtime function" OutputDebugString warning for
+ unknown modes. Assume that if O_CLOEXEC is zero, then "e" isn't
+ supported. */
+ static int fopen_e_ever_failed_einval = O_CLOEXEC == 0;
+
+ if (!fopen_e_ever_failed_einval)
{
char *copy;
this path. */
strcat (copy, "e");
result = fopen (filename, copy);
- }
- if (result == NULL)
- {
- /* Fallback. */
- result = fopen (filename, opentype);
- if (result != NULL)
- fopen_e_ever_failed = 1;
+ if (result == NULL && errno == EINVAL)
+ {
+ result = fopen (filename, opentype);
+ if (result != NULL)
+ fopen_e_ever_failed_einval = 1;
+ }
}
+ else
+ result = fopen (filename, opentype);
if (result != NULL)
maybe_mark_cloexec (fileno (result));