/* Low-level file-handling.
- Copyright (C) 2012-2018 Free Software Foundation, Inc.
+ Copyright (C) 2012-2019 Free Software Foundation, Inc.
This file is part of GDB.
#define HAVE_SOCKETS 1
#endif
+#ifdef HAVE_KINFO_GETFILE
+#include <sys/user.h>
+#include <libutil.h>
+#endif
+
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif /* HAVE_SYS_RESOURCE_H */
}
/* We may fall through to the next case. */
#endif
+#ifdef HAVE_KINFO_GETFILE
+ int nfd;
+ gdb::unique_xmalloc_ptr<struct kinfo_file[]> fdtbl
+ (kinfo_getfile (getpid (), &nfd));
+ if (fdtbl != NULL)
+ {
+ for (int i = 0; i < nfd; i++)
+ {
+ if (fdtbl[i].kf_fd >= 0)
+ {
+ int result = func (arg, fdtbl[i].kf_fd);
+ if (result != 0)
+ return result;
+ }
+ }
+ return 0;
+ }
+ /* We may fall through to the next case. */
+#endif
{
int max, fd;
return result;
}
-/* Helper function which does the work for make_cleanup_close. */
-
-static void
-do_close_cleanup (void *arg)
-{
- int *fd = (int *) arg;
-
- close (*fd);
-}
-
-/* See filestuff.h. */
-
-struct cleanup *
-make_cleanup_close (int fd)
-{
- int *saved_fd = XNEW (int);
-
- *saved_fd = fd;
- return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
-}
-
/* See common/filestuff.h. */
bool
bool
mkdir_recursive (const char *dir)
{
- gdb::unique_xmalloc_ptr<char> holder (xstrdup (dir));
+ auto holder = make_unique_xstrdup (dir);
char * const start = holder.get ();
char *component_start = start;
char *component_end = start;