c - 在 Linux 上获取当前进程的环境变量

标签 c linux environment-variables porting

我正在尝试将应用程序从 Windows 移植到 Linux。在 Windows 中我有一个 windows.h 中的 GetEnvironmentStrings() 函数为我提供了当前进程中的环境变量及其值 形式 NAME=VALUE。

是否有一个等效的 Linux 函数调用?我需要一个 C 函数。 这在 Linux 上如何实现?

最佳答案

您可以通过变量extern char **environ;访问环境变量。

Read more :

The value of an environment variable is a string of characters. For a C-language program, an array of strings called the environment shall be made available when a process begins. The array is pointed to by the external variable environ, which is defined as:

extern char **environ;

These strings have the form name=value.

关于c - 在 Linux 上获取当前进程的环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037388/

相关文章:

arrays - 变量零初始化会降低性能吗?

gcc与cmake编译的编译区别——ldd命令

c - 无法理解以下程序中的 pthread_create() 行为?

linux - iptables:什么是链?

php - Laravel 5 : How to enable environment based public resources like css, js,图像

windows - 在一行中设置环境变量和执行命令的最佳方法

c - 函数指针 IAR (typedef void)

c - 在 C 中分配结构的指针实例

c - 合并排序未显示正确的输出

python - 如何在 Python 中获取 PATH 环境变量分隔符?