Mega Code Archive

 
Categories / C / Linux
 

Show,access enviroment vars

#ifndef __USE_GNU #define _GNU_SOURCE #endif #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(void) { char **env = environ; char pwd[256] = {0}; printf("getenv() says, go home: %s\n", getenv("HOME")); getcwd(pwd, sizeof(pwd)); printf("getcwd says, no I am staying here: %s\n", pwd); printf("All other enviroment var's .... \n"); for(; *env; env++) printf("%s\n", *env); return 0; }