Skip to content

Instantly share code, notes, and snippets.

@higedice
Last active June 28, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save higedice/f78ce4e5de4a12d4cc8c2210e9c50fca to your computer and use it in GitHub Desktop.
Save higedice/f78ce4e5de4a12d4cc8c2210e9c50fca to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
char path[1024];
printf("getenv(\"PWD\"): %s\n", getenv("PWD")); // " /home/me"
printf("cd /\n");
chdir("/");
printf("getenv(\"PWD\"): %s\n", getenv("PWD")); // "/home/me"
printf("getcwd(): %s\n", getcwd(path, sizeof((path)))); // "/"
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment