18dffb485Schristos /* Header for environment manipulation library. 2*5ba1f45fSchristos Copyright (C) 1989-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This program is free software; you can redistribute it and/or modify 58dffb485Schristos it under the terms of the GNU General Public License as published by 68dffb485Schristos the Free Software Foundation; either version 3 of the License, or 78dffb485Schristos (at your option) any later version. 88dffb485Schristos 98dffb485Schristos This program is distributed in the hope that it will be useful, 108dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 118dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128dffb485Schristos GNU General Public License for more details. 138dffb485Schristos 148dffb485Schristos You should have received a copy of the GNU General Public License 158dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 168dffb485Schristos 178dffb485Schristos #ifndef COMMON_ENVIRON_H 188dffb485Schristos #define COMMON_ENVIRON_H 198dffb485Schristos 208dffb485Schristos #include <vector> 218dffb485Schristos #include <set> 228dffb485Schristos 238dffb485Schristos /* Class that represents the environment variables as seen by the 248dffb485Schristos inferior. */ 258dffb485Schristos 268dffb485Schristos class gdb_environ 278dffb485Schristos { 288dffb485Schristos public: 298dffb485Schristos /* Regular constructor and destructor. */ 308dffb485Schristos gdb_environ () 318dffb485Schristos { 328dffb485Schristos /* Make sure that the vector contains at least a NULL element. 338dffb485Schristos If/when we add more variables to it, NULL will always be the 348dffb485Schristos last element. */ 358dffb485Schristos m_environ_vector.push_back (NULL); 368dffb485Schristos } 378dffb485Schristos 388dffb485Schristos ~gdb_environ () 398dffb485Schristos { 408dffb485Schristos clear (); 418dffb485Schristos } 428dffb485Schristos 438dffb485Schristos /* Move constructor. */ 448dffb485Schristos gdb_environ (gdb_environ &&e) 458dffb485Schristos : m_environ_vector (std::move (e.m_environ_vector)), 468dffb485Schristos m_user_set_env (std::move (e.m_user_set_env)), 478dffb485Schristos m_user_unset_env (std::move (e.m_user_unset_env)) 488dffb485Schristos { 498dffb485Schristos /* Make sure that the moved-from vector is left at a valid 508dffb485Schristos state (only one NULL element). */ 518dffb485Schristos e.m_environ_vector.clear (); 528dffb485Schristos e.m_environ_vector.push_back (NULL); 538dffb485Schristos e.m_user_set_env.clear (); 548dffb485Schristos e.m_user_unset_env.clear (); 558dffb485Schristos } 568dffb485Schristos 578dffb485Schristos /* Move assignment. */ 588dffb485Schristos gdb_environ &operator= (gdb_environ &&e); 598dffb485Schristos 608dffb485Schristos /* Create a gdb_environ object using the host's environment 618dffb485Schristos variables. */ 628dffb485Schristos static gdb_environ from_host_environ (); 638dffb485Schristos 648dffb485Schristos /* Clear the environment variables stored in the object. */ 658dffb485Schristos void clear (); 668dffb485Schristos 678dffb485Schristos /* Return the value in the environment for the variable VAR. The 688dffb485Schristos returned pointer is only valid as long as the gdb_environ object 698dffb485Schristos is not modified. */ 708dffb485Schristos const char *get (const char *var) const; 718dffb485Schristos 728dffb485Schristos /* Store VAR=VALUE in the environment. */ 738dffb485Schristos void set (const char *var, const char *value); 748dffb485Schristos 758dffb485Schristos /* Unset VAR in environment. */ 768dffb485Schristos void unset (const char *var); 778dffb485Schristos 788dffb485Schristos /* Return the environment vector represented as a 'char **'. */ 798dffb485Schristos char **envp () const; 808dffb485Schristos 818dffb485Schristos /* Return the user-set environment vector. */ 828dffb485Schristos const std::set<std::string> &user_set_env () const; 838dffb485Schristos 848dffb485Schristos /* Return the user-unset environment vector. */ 858dffb485Schristos const std::set<std::string> &user_unset_env () const; 868dffb485Schristos 878dffb485Schristos private: 888dffb485Schristos /* Unset VAR in environment. If UPDATE_UNSET_LIST is true, then 898dffb485Schristos also update M_USER_UNSET_ENV to reflect the unsetting of the 908dffb485Schristos environment variable. */ 918dffb485Schristos void unset (const char *var, bool update_unset_list); 928dffb485Schristos 938dffb485Schristos /* A vector containing the environment variables. */ 948dffb485Schristos std::vector<char *> m_environ_vector; 958dffb485Schristos 968dffb485Schristos /* The environment variables explicitly set by the user. */ 978dffb485Schristos std::set<std::string> m_user_set_env; 988dffb485Schristos 998dffb485Schristos /* The environment variables explicitly unset by the user. */ 1008dffb485Schristos std::set<std::string> m_user_unset_env; 1018dffb485Schristos }; 1028dffb485Schristos 1038dffb485Schristos #endif /* COMMON_ENVIRON_H */ 104