#include <stdlib.h> #include <stdio.h> char* getEnvWrapper(char* key) { char* value = getenv(key); if (!value) { value = "not found"; } return value; } int putEnvWrapper(char* key, char* value) { return setenv(key, value, 1); } int main(int argc, char** argv){ if(argc == 2){ char* r = getEnvWrapper(argv[1]); printf("GetEnv %s = %s\n", argv[1], r); }else if(argc == 3 ) { printf("SetEnv => %s:%s\n", argv[1], argv[2]); int r = putEnvWrapper(argv[1], argv[2]); printf("GetEnv result code = %d\n", r); }else { printf("usage : ./envop key [value]\n"); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)