|
2013 | 2013 | \pdfbookmark[1]{getenv, putenv, setenv}{envfuncs} |
2014 | 2014 |
|
2015 | 2015 | \begin{slide} |
2016 | | -\sltitle{Manipulace s promìnnými prostøedí} |
| 2016 | +\sltitle{Manipulating the environment} |
2017 | 2017 | \begin{itemize} |
2018 | | -\item je mo¾né pøímo mìnit promìnnou \texttt{environ}, SUSv3 to ale nedoporuèuje |
| 2018 | +\item it is possible to replace \texttt{environ} with a different array but in |
| 2019 | +general you should not do that |
2019 | 2020 | \item \texttt{char *\funnm{getenv} (const char *\emph{name});} |
2020 | 2021 | \begin{itemize} |
2021 | | - \item vrátí hodnotu promìnné name |
| 2022 | + \item return value of \emph{name} |
2022 | 2023 | \end{itemize} |
2023 | 2024 | \item \texttt{int \funnm{putenv} (char *\emph{string});} |
2024 | 2025 | \begin{itemize} |
2025 | | - \item vlo¾í string ve tvaru \texttt{\emph{jméno}=\emph{hodnota}} do |
2026 | | - prostøedí (pøidá novou nebo modifikuje existující promìnnou) |
| 2026 | + \item inserts a string \texttt{\emph{name}=\emph{value}} into the |
| 2027 | + environment (adds a new or modifies an existing variable) |
2027 | 2028 | \end{itemize} |
2028 | | -\item zmìny se pøená¹ejí do synovských procesù |
2029 | | -\item zmìny v prostøedí syna samozøejmì prostøedí otce neovlivní |
2030 | | -\item existují i funkce \funnm{setenv}() a \funnm{unsetenv}() |
| 2029 | +\item changes are propagated into children upon their creation |
| 2030 | +\item there are also functions \funnm{setenv}() a \funnm{unsetenv}() |
2031 | 2031 | \end{itemize} |
2032 | 2032 | \end{slide} |
2033 | 2033 |
|
2034 | 2034 | \begin{itemize} |
2035 | | -\item u \texttt{putenv} se vlo¾ený øetìzec stane souèástí prostøedí (jeho |
2036 | | -pozdìj¹í zmìna tak zmìní prostøedí) a nesmíte proto pou¾ívat retìzce v |
2037 | | -automatických pro\-mìn\-ných, toto øe¹í \texttt{setenv}, který hodnotu promìnné |
2038 | | -zkopíruje. Viz pøíklad \example{main/putenv.c}. |
2039 | | -\item dùle¾ité je zapamatovat si, ¾e synovský proces zdìdí v okam¾iku svého |
2040 | | -vzniku od rodièe v¹echny promìnné prostøedí, ale jakákoliv manipulace s nimi v |
2041 | | -synovi je lokální a do otce se nepøená¹í. Ka¾dý proces má svou kopii |
2042 | | -pro\-mìn\-ných, proto ani následná zmìna prostøedí otce nezmìní promìnné |
2043 | | -ji¾ existujícího potomka. |
2044 | | -\item dal¹í rozdíl mezi \texttt{putenv} a \texttt{setenv} je ten, ¾e v |
2045 | | -\texttt{setenv} mohu definovat, zda existující promìnnou chci nebo nechci |
2046 | | -pøepsat. \texttt{putenv} v¾dy pøepisuje. |
2047 | | -\item |
| 2035 | +\item Read the description for \texttt{environ} in SUSv4 before assigning a new |
| 2036 | +value to the variable as there are important information there you should know. |
| 2037 | +\item When using \texttt{putenv}, the string will become part of the |
| 2038 | +environment, nothing is copied. You must not use automatic variables for such |
| 2039 | +strings. Use \texttt{setenv} to copy the value into the environment. Example: |
| 2040 | +\example{main/putenv.c}. |
| 2041 | +\item Changes in a child never changes its parent environment as those arrays |
| 2042 | +reside in separate address spaces. |
| 2043 | +\item Another difference between \texttt{putenv} and \texttt{setenv} is that in |
| 2044 | +\texttt{setenv} one can say whether an existing variable should be overwritten |
| 2045 | +or not. Function \texttt{putenv} always overwrites an existing variable. |
| 2046 | +\item Example: |
| 2047 | + |
2048 | 2048 | \begin{verbatim} |
2049 | 2049 | int |
2050 | 2050 | main(void) |
|
2053 | 2053 | return (0); |
2054 | 2054 | } |
2055 | 2055 | $ ./a.out |
2056 | | -jp |
| 2056 | +janp |
2057 | 2057 | \end{verbatim} |
2058 | | -\item jeliko¾ promìnná \texttt{environ} je obyèejné pole ukazatelù na øetìzce, |
2059 | | -není nebì¾né narazit na kód, který s tímto polem pracuje pøímo. Pozor v¹ak na |
2060 | | -to, ¾e v takovém pøípadì pak ji¾ nesmíte pou¾ívat zde uvedené funkce, jinak se |
2061 | | -mù¾ete dostat do problémù s jejich konkrétní implementací. A hlavnì, nový kód |
2062 | | -takto nepi¹te, proto¾e norma SUSv3 pøímou práci s tímto polem nedoporuèuje. |
2063 | | -\item pøíklad: \example{main/getenv.c} |
2064 | | -\item pozor na to, ¾e je rozdíl mezi nastavením hodnoty promìnné na |
2065 | | -prázdný string a odmazáním promìnné ze seznamu promìnných (pomocí |
2066 | | -\texttt{unsetenv}). |
| 2058 | + |
| 2059 | +\item As \texttt{environ} is just an array of pointers, you may find code that |
| 2060 | +directly manipulates it. However, any application that directly modifies the |
| 2061 | +pointers to which the environ variable points has undefined behavior according |
| 2062 | +to SUSv4, and that is possibly exacerbated if the functions introduced above are |
| 2063 | +used while doing that. Do not write code like that. |
| 2064 | +\item Example: \example{main/getenv.c} |
| 2065 | +\item Note that there is a difference between setting a variable to an empty |
| 2066 | +string and removing the variable from the environment via \texttt{unsetenv}. |
2067 | 2067 | \end{itemize} |
2068 | 2068 |
|
2069 | 2069 | %%%%% |
|
0 commit comments