Created
December 15, 2015 02:28
-
-
Save mattn/70a1effee4564b62734c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#define ENVIRON "/proc/self/environ" | |
int | |
main(int argc, char* argv[]) { | |
FILE* fp = fopen(ENVIRON, "r"); | |
struct stat st; | |
char buf[BUFSIZ] = {0}; | |
int i; | |
setenv("FOO", "BAR", 1); | |
if (stat(ENVIRON, &st) != 0) { | |
perror("stat"); | |
exit(1); | |
} | |
fgets(buf, sizeof buf, fp); | |
fclose(fp); | |
for (i = 0; i < sizeof buf; i++) { | |
if (buf[i] == 0) { | |
if (i > 0 && buf[i-1] == '\n') break; | |
buf[i] = '\n'; | |
} | |
} | |
puts(buf); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment