我正在尝试将应用程序从 Windows 移植到 Linux。在 Windows 中我有一个 windows.h 中的 GetEnvironmentStrings() 函数为我提供了当前进程中的环境变量及其值 形式 NAME=VALUE。
是否有一个等效的 Linux 函数调用?我需要一个 C 函数。 这在 Linux 上如何实现?
最佳答案
您可以通过变量extern char **environ;
访问环境变量。
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/