mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
d419f42dd3
This introduces gdb_file_up, a unique pointer holding a FILE*, and then changes some code in gdb to use it. In particular gdb_fopen_cloexec now returns a gdb_file_up. This allow removing some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * xml-support.c (xml_fetch_content_from_file): Update. * ui-file.c (stdio_file::open): Update. * tracefile-tfile.c (tfile_start): Update. * remote.c (remote_file_put, remote_file_get): Update. * nat/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_get_state, linux_proc_tid_get_name): Update. * nat/linux-osdata.c (linux_common_core_of_thread): Update. (command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus) (print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update. * nat/linux-btrace.c (linux_determine_kernel_start): Update. * linux-nat.c (linux_proc_pending_signals): Update. * dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up. (file_closer): Remove. * compile/compile.c (compile_to_object): Update. * common/filestuff.h (struct gdb_file_deleter): New. (gdb_file_up): New typedef. (gdb_fopen_cloexec): Change return type. * common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up. * cli/cli-dump.c (fopen_with_cleanup): Remove. (dump_binary_file, restore_binary_file): Update. * auto-load.c (auto_load_objfile_script_1): Update.
88 lines
2.7 KiB
C++
88 lines
2.7 KiB
C++
/* Low-level file-handling.
|
|
Copyright (C) 2012-2017 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
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
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef FILESTUFF_H
|
|
#define FILESTUFF_H
|
|
|
|
/* Note all the file descriptors which are open when this is called.
|
|
These file descriptors will not be closed by close_most_fds. */
|
|
|
|
extern void notice_open_fds (void);
|
|
|
|
/* Mark a file descriptor as inheritable across an exec. */
|
|
|
|
extern void mark_fd_no_cloexec (int fd);
|
|
|
|
/* Mark a file descriptor as no longer being inheritable across an
|
|
exec. This is only meaningful when FD was previously passed to
|
|
mark_fd_no_cloexec. */
|
|
|
|
extern void unmark_fd_no_cloexec (int fd);
|
|
|
|
/* Close all open file descriptors other than those marked by
|
|
'notice_open_fds', and stdin, stdout, and stderr. Errors that
|
|
occur while closing are ignored. */
|
|
|
|
extern void close_most_fds (void);
|
|
|
|
/* Like 'open', but ensures that the returned file descriptor has the
|
|
close-on-exec flag set. */
|
|
|
|
extern int gdb_open_cloexec (const char *filename, int flags,
|
|
/* mode_t */ unsigned long mode);
|
|
|
|
struct gdb_file_deleter
|
|
{
|
|
void operator() (FILE *file) const
|
|
{
|
|
fclose (file);
|
|
}
|
|
};
|
|
|
|
/* A unique pointer to a FILE. */
|
|
|
|
typedef std::unique_ptr<FILE, gdb_file_deleter> gdb_file_up;
|
|
|
|
/* Like 'fopen', but ensures that the returned file descriptor has the
|
|
close-on-exec flag set. */
|
|
|
|
extern gdb_file_up gdb_fopen_cloexec (const char *filename,
|
|
const char *opentype);
|
|
|
|
/* Like 'socketpair', but ensures that the returned file descriptors
|
|
have the close-on-exec flag set. */
|
|
|
|
extern int gdb_socketpair_cloexec (int domain, int style, int protocol,
|
|
int filedes[2]);
|
|
|
|
/* Like 'socket', but ensures that the returned file descriptor has
|
|
the close-on-exec flag set. */
|
|
|
|
extern int gdb_socket_cloexec (int domain, int style, int protocol);
|
|
|
|
/* Like 'pipe', but ensures that the returned file descriptors have
|
|
the close-on-exec flag set. */
|
|
|
|
extern int gdb_pipe_cloexec (int filedes[2]);
|
|
|
|
/* Return a new cleanup that closes FD. */
|
|
|
|
extern struct cleanup *make_cleanup_close (int fd);
|
|
|
|
#endif /* FILESTUFF_H */
|