如何在没有setenv()的情况下在ISO c99标准C中设置环境变量? [英] How to set environment variable in ISO c99 Standard C without setenv()?

查看:96
本文介绍了如何在没有setenv()的情况下在ISO c99标准C中设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于C99标准编译器,我无法使用 stdlib.h 中的 setenv(),因为它不可用。还有其他功能可以在C99中设置环境变量吗?

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?

推荐答案

getenv 因此是C90标准的一部分,该标准已包含在C99,但 setenv 仅符合IEEE标准,因此不必严格包含在标准C99中。此外,相应的IEEE是2001年的。

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.

这意味着C99中没有任何标准的方法,您必须使用特定于平台的代码来设置

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

在freebsd上手册页


getenv()函数符合ISO / IEC 9899:1990( ISO C90'')。
setenv(),putenv()和unsetenv()函数符合IEEE Std
1003.1-2001(
POSIX.1'')。

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 等应该在任何POSIX系统上定义。


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

如果您使用的是Windows,请参阅其他问题,其中讨论了 _putenv_s

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

这篇关于如何在没有setenv()的情况下在ISO c99标准C中设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆