Update copyright year range in all GDB files
[deliverable/binutils-gdb.git] / gdb / common / filestuff.h
CommitLineData
614c279d 1/* Low-level file-handling.
e2882c85 2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
614c279d
TT
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef FILESTUFF_H
20#define FILESTUFF_H
21
22/* Note all the file descriptors which are open when this is called.
23 These file descriptors will not be closed by close_most_fds. */
24
25extern void notice_open_fds (void);
26
21ff4686
TT
27/* Mark a file descriptor as inheritable across an exec. */
28
29extern void mark_fd_no_cloexec (int fd);
30
31/* Mark a file descriptor as no longer being inheritable across an
32 exec. This is only meaningful when FD was previously passed to
33 mark_fd_no_cloexec. */
34
35extern void unmark_fd_no_cloexec (int fd);
36
614c279d
TT
37/* Close all open file descriptors other than those marked by
38 'notice_open_fds', and stdin, stdout, and stderr. Errors that
39 occur while closing are ignored. */
40
41extern void close_most_fds (void);
42
43/* Like 'open', but ensures that the returned file descriptor has the
44 close-on-exec flag set. */
45
5d71132c
TT
46extern int gdb_open_cloexec (const char *filename, int flags,
47 /* mode_t */ unsigned long mode);
614c279d 48
d419f42d
TT
49struct gdb_file_deleter
50{
51 void operator() (FILE *file) const
52 {
53 fclose (file);
54 }
55};
56
57/* A unique pointer to a FILE. */
58
59typedef std::unique_ptr<FILE, gdb_file_deleter> gdb_file_up;
60
614c279d
TT
61/* Like 'fopen', but ensures that the returned file descriptor has the
62 close-on-exec flag set. */
63
d419f42d
TT
64extern gdb_file_up gdb_fopen_cloexec (const char *filename,
65 const char *opentype);
614c279d
TT
66
67/* Like 'socketpair', but ensures that the returned file descriptors
68 have the close-on-exec flag set. */
69
fe978cb0 70extern int gdb_socketpair_cloexec (int domain, int style, int protocol,
614c279d
TT
71 int filedes[2]);
72
73/* Like 'socket', but ensures that the returned file descriptor has
74 the close-on-exec flag set. */
75
fe978cb0 76extern int gdb_socket_cloexec (int domain, int style, int protocol);
614c279d
TT
77
78/* Like 'pipe', but ensures that the returned file descriptors have
79 the close-on-exec flag set. */
80
81extern int gdb_pipe_cloexec (int filedes[2]);
82
ca095836
GB
83/* Return a new cleanup that closes FD. */
84
85extern struct cleanup *make_cleanup_close (int fd);
86
614c279d 87#endif /* FILESTUFF_H */
This page took 0.331704 seconds and 4 git commands to generate.