How to set environment variable in ISO c99 Standard C without setenv()?

旧城冷巷雨未停 提交于 2020-01-25 12:00:13

问题


I can't use setenv() from stdlib.h for C99 standard compiler as it is not available. Is there any other function to set an environment variable in C99?


回答1:


getenv is thus part of the C90 standard which is included in C99 but setenv is only conform to an IEEE standard so it hasn't to be included in strictly standard C99. Moreover, the corresponding IEEE is from 2001.

This means there isn't any standard way of doing this in C99, you have to use platform-specific code to set the env.

On the freebsd man page:

The getenv() function conforms to ISO/IEC 9899:1990 (ISO C90''). The setenv(), putenv() and unsetenv() functions conforms to IEEE Std 1003.1-2001 (POSIX.1'').


setenv, putenv and so on should be defined on any POSIX system.

If you're using windows, see this other question which talks about _putenv_s.



来源:https://stackoverflow.com/questions/21093392/how-to-set-environment-variable-in-iso-c99-standard-c-without-setenv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!