C++ify gdb/common/environ.c
[deliverable/binutils-gdb.git] / gdb / common / environ.h
1 /* Header for environment manipulation library.
2 Copyright (C) 1989-2017 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #if !defined (ENVIRON_H)
18 #define ENVIRON_H 1
19
20 #include <vector>
21
22 /* Class that represents the environment variables as seen by the
23 inferior. */
24
25 class gdb_environ
26 {
27 public:
28 /* Regular constructor and destructor. */
29 gdb_environ ()
30 {
31 /* Make sure that the vector contains at least a NULL element.
32 If/when we add more variables to it, NULL will always be the
33 last element. */
34 m_environ_vector.push_back (NULL);
35 }
36
37 ~gdb_environ ()
38 {
39 clear ();
40 }
41
42 /* Move constructor. */
43 gdb_environ (gdb_environ &&e)
44 : m_environ_vector (std::move (e.m_environ_vector))
45 {
46 /* Make sure that the moved-from vector is left at a valid
47 state (only one NULL element). */
48 e.m_environ_vector.clear ();
49 e.m_environ_vector.push_back (NULL);
50 }
51
52 /* Move assignment. */
53 gdb_environ &operator= (gdb_environ &&e);
54
55 /* Create a gdb_environ object using the host's environment
56 variables. */
57 static gdb_environ from_host_environ ();
58
59 /* Clear the environment variables stored in the object. */
60 void clear ();
61
62 /* Return the value in the environment for the variable VAR. The
63 returned pointer is only valid as long as the gdb_environ object
64 is not modified. */
65 const char *get (const char *var) const;
66
67 /* Store VAR=VALUE in the environment. */
68 void set (const char *var, const char *value);
69
70 /* Unset VAR in environment. */
71 void unset (const char *var);
72
73 /* Return the environment vector represented as a 'char **'. */
74 char **envp () const;
75
76 private:
77 /* A vector containing the environment variables. */
78 std::vector<char *> m_environ_vector;
79 };
80
81 #endif /* defined (ENVIRON_H) */
This page took 0.02987 seconds and 4 git commands to generate.