\hypertarget{opal__environ_8h}{\section{opal/util/opal\+\_\+environ.h File Reference}
\label{opal__environ_8h}\index{opal/util/opal\+\_\+environ.\+h@{opal/util/opal\+\_\+environ.\+h}}
}


Generic helper routines for environment manipulation.  


{\ttfamily \#include \char`\"{}opal\+\_\+config.\+h\char`\"{}}\\*
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
B\+E\+G\+I\+N\+\_\+\+C\+\_\+\+D\+E\+C\+L\+S O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C char $\ast$$\ast$ \hyperlink{opal__environ_8h_a9e78be5a9216cfa394d6e83925a41c65}{opal\+\_\+environ\+\_\+merge} (char $\ast$$\ast$minor, char $\ast$$\ast$major) \+\_\+\+\_\+opal\+\_\+attribute\+\_\+warn\+\_\+unused\+\_\+result\+\_\+\+\_\+
\begin{DoxyCompactList}\small\item\em Merge two environ-\/like arrays into a single, new array, ensuring that there are no duplicate entries. \end{DoxyCompactList}\item 
O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int \hyperlink{opal__environ_8h_aedb7ee7119537b2f6c79f3820de54967}{opal\+\_\+setenv} (const char $\ast$name, const char $\ast$value, bool overwrite, char $\ast$$\ast$$\ast$env) \+\_\+\+\_\+opal\+\_\+attribute\+\_\+nonnull\+\_\+\+\_\+(1)
\begin{DoxyCompactList}\small\item\em Portable version of setenv(3), allowing editing of any environ-\/like array. \end{DoxyCompactList}\item 
O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int \hyperlink{opal__environ_8h_ac572c0a379adf964a203ee7f762f7c84}{opal\+\_\+unsetenv} (const char $\ast$name, char $\ast$$\ast$$\ast$env) \+\_\+\+\_\+opal\+\_\+attribute\+\_\+nonnull\+\_\+\+\_\+(1)
\begin{DoxyCompactList}\small\item\em Portable version of unsetenv(3), allowing editing of any environ-\/like array. \end{DoxyCompactList}\item 
\hypertarget{opal__environ_8h_ab58c8c3e72c74fedf5a4ff83f3a13e82}{O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C const char $\ast$ {\bfseries opal\+\_\+home\+\_\+directory} (void)}\label{opal__environ_8h_ab58c8c3e72c74fedf5a4ff83f3a13e82}

\item 
\hypertarget{opal__environ_8h_a9e70734c924dbd831ffab32fea22d5d1}{O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C const char $\ast$ {\bfseries opal\+\_\+tmp\+\_\+directory} (void)}\label{opal__environ_8h_a9e70734c924dbd831ffab32fea22d5d1}

\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\hypertarget{opal__environ_8h_aaf99c8a2f259d749ee3c565d414f2db9}{O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C char $\ast$$\ast$ {\bfseries environ}}\label{opal__environ_8h_aaf99c8a2f259d749ee3c565d414f2db9}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
Generic helper routines for environment manipulation. 



\subsection{Function Documentation}
\hypertarget{opal__environ_8h_a9e78be5a9216cfa394d6e83925a41c65}{\index{opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}!opal\+\_\+environ\+\_\+merge@{opal\+\_\+environ\+\_\+merge}}
\index{opal\+\_\+environ\+\_\+merge@{opal\+\_\+environ\+\_\+merge}!opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}}
\subsubsection[{opal\+\_\+environ\+\_\+merge}]{\setlength{\rightskip}{0pt plus 5cm}B\+E\+G\+I\+N\+\_\+\+C\+\_\+\+D\+E\+C\+L\+S O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C char$\ast$$\ast$ opal\+\_\+environ\+\_\+merge (
\begin{DoxyParamCaption}
\item[{char $\ast$$\ast$}]{minor, }
\item[{char $\ast$$\ast$}]{major}
\end{DoxyParamCaption}
)}}\label{opal__environ_8h_a9e78be5a9216cfa394d6e83925a41c65}


Merge two environ-\/like arrays into a single, new array, ensuring that there are no duplicate entries. 


\begin{DoxyParams}{Parameters}
{\em minor} & Set 1 of the environ's to merge \\
\hline
{\em major} & Set 2 of the environ's to merge \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em New} & array of environ\\
\hline
\end{DoxyRetVals}
Merge two environ-\/like arrays into a single, new array, ensuring that there are no duplicate entires. If there are duplicates, entries in the {\itshape major} array are favored over those in the {\itshape minor} array.

Both {\itshape major} and {\itshape minor} are expected to be argv-\/style arrays (i.\+e., terminated with a N\+U\+L\+L pointer).

The array that is returned is an unencumbered array that should later be freed with a call to \hyperlink{argv_8h_a812edb42a56e62651124d6fac215aeeb}{opal\+\_\+argv\+\_\+free()}.

Either (or both) of {\itshape major} and {\itshape minor} can be N\+U\+L\+L. If one of the two is N\+U\+L\+L, the other list is simply copied to the output. If both are N\+U\+L\+L, N\+U\+L\+L is returned. 

References opal\+\_\+argv\+\_\+copy(), and opal\+\_\+setenv().

\hypertarget{opal__environ_8h_aedb7ee7119537b2f6c79f3820de54967}{\index{opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}!opal\+\_\+setenv@{opal\+\_\+setenv}}
\index{opal\+\_\+setenv@{opal\+\_\+setenv}!opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}}
\subsubsection[{opal\+\_\+setenv}]{\setlength{\rightskip}{0pt plus 5cm}O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int opal\+\_\+setenv (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name, }
\item[{const char $\ast$}]{value, }
\item[{bool}]{overwrite, }
\item[{char $\ast$$\ast$$\ast$}]{env}
\end{DoxyParamCaption}
)}}\label{opal__environ_8h_aedb7ee7119537b2f6c79f3820de54967}


Portable version of setenv(3), allowing editing of any environ-\/like array. 


\begin{DoxyParams}{Parameters}
{\em name} & String name of the environment variable to look for \\
\hline
{\em value} & String value to set (may be N\+U\+L\+L) \\
\hline
{\em overwrite} & Whether to overwrite any existing value with the same name \\
\hline
{\em env} & The environment to use\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em O\+P\+A\+L\+\_\+\+E\+R\+R\+\_\+\+O\+U\+T\+\_\+\+O\+F\+\_\+\+R\+E\+S\+O\+U\+R\+C\+E} & If internal malloc() fails. \\
\hline
{\em O\+P\+A\+L\+\_\+\+E\+X\+I\+S\+T\+S} & If the name already exists in {\itshape env} and {\itshape overwrite} is false (and therefore the {\itshape value} was not saved in {\itshape env}) \\
\hline
{\em O\+P\+A\+L\+\_\+\+S\+U\+C\+E\+S\+S} & If the value replaced another value or is appended to {\itshape env}.\\
\hline
\end{DoxyRetVals}
{\itshape env} is expected to be a N\+U\+L\+L-\/terminated array of pointers (argv-\/style). Note that unlike some implementations of putenv(3), if {\itshape value} is insertted in {\itshape env}, it is copied. So the caller can modify/free both {\itshape name} and {\itshape value} after \hyperlink{opal__environ_8h_aedb7ee7119537b2f6c79f3820de54967}{opal\+\_\+setenv()} returns.

The {\itshape env} array will be grown if necessary.

It is permissable to invoke this function with the system-\/defined {\itshape environ} variable. For example\+:


\begin{DoxyCode}
1 #include "opal/util/opal\_environ.h"
2 opal\_setenv("foo", "bar", true, &environ);
\end{DoxyCode}


N\+O\+T\+E\+: If you use the real environ, \hyperlink{opal__environ_8h_aedb7ee7119537b2f6c79f3820de54967}{opal\+\_\+setenv()} will turn around and perform putenv() to put the value in the environment. This may very well lead to a memory leak, so its use is strongly discouraged.

It is also permissable to call this function with an empty {\itshape env}, as long as it is pre-\/initialized with N\+U\+L\+L\+:


\begin{DoxyCode}
1 char **my\_env = NULL;
2 opal\_setenv("foo", "bar", true, &my\_env);
\end{DoxyCode}
 

References opal\+\_\+argv\+\_\+append(), and opal\+\_\+argv\+\_\+count().



Referenced by opal\+\_\+environ\+\_\+merge(), orte\+\_\+plm\+\_\+submit\+\_\+launch(), and parse\+\_\+args().

\hypertarget{opal__environ_8h_ac572c0a379adf964a203ee7f762f7c84}{\index{opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}!opal\+\_\+unsetenv@{opal\+\_\+unsetenv}}
\index{opal\+\_\+unsetenv@{opal\+\_\+unsetenv}!opal\+\_\+environ.\+h@{opal\+\_\+environ.\+h}}
\subsubsection[{opal\+\_\+unsetenv}]{\setlength{\rightskip}{0pt plus 5cm}O\+P\+A\+L\+\_\+\+D\+E\+C\+L\+S\+P\+E\+C int opal\+\_\+unsetenv (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{name, }
\item[{char $\ast$$\ast$$\ast$}]{env}
\end{DoxyParamCaption}
)}}\label{opal__environ_8h_ac572c0a379adf964a203ee7f762f7c84}


Portable version of unsetenv(3), allowing editing of any environ-\/like array. 


\begin{DoxyParams}{Parameters}
{\em name} & String name of the environment variable to look for \\
\hline
{\em env} & The environment to use\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em O\+P\+A\+L\+\_\+\+E\+R\+R\+\_\+\+O\+U\+T\+\_\+\+O\+F\+\_\+\+R\+E\+S\+O\+U\+R\+C\+E} & If an internal malloc fails. \\
\hline
{\em O\+P\+A\+L\+\_\+\+E\+R\+R\+\_\+\+N\+O\+T\+\_\+\+F\+O\+U\+N\+D} & If {\itshape name} is not found in {\itshape env}. \\
\hline
{\em O\+P\+A\+L\+\_\+\+S\+U\+C\+C\+E\+S\+S} & If {\itshape name} is found and successfully deleted.\\
\hline
\end{DoxyRetVals}
If {\itshape name} is found in {\itshape env}, the string corresponding to that entry is freed and its entry is eliminated from the array. 