Skip to content

Commit

Permalink
chdir getcwd
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjun1055 committed Dec 23, 2013
1 parent 27e6b0c commit db1db84
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 4.8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
if (chdir("/tmp") < 0) {
printf("chdir failed!\n");
exit(-1);
}

printf("chidr to /tmp successed\n");

return 0;
}
21 changes: 21 additions & 0 deletions 4.9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
char *ptr;
int size = 100;

if (chdir("/home/vagrant") < 0) {
printf("chdir failed\n");
}

if (getcwd(ptr, size) == NULL) {
printf("getcwd failed\n");
}

printf("cwd = %s\n", ptr);

return 0;
}

0 comments on commit db1db84

Please sign in to comment.