Created
February 23, 2012 23:06
-
-
Save tylermenezes/1895600 to your computer and use it in GitHub Desktop.
Code for finding enviroment variable location
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 <stdlib.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) { | |
char *ptr; | |
if(argc < 3) { | |
printf("Usage: %s <envvar> <program>\n", argv[0]); | |
exit(0); | |
} | |
ptr = getenv(argv[1]); /* Get env var location. */ | |
ptr += (strlen(argv[0]) - strlen(argv[2]))*2; /* Adjust for program name. */ | |
printf("%p\n", ptr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment