1: #include <stdio.h> 2: # define move(x, y) close(y); dup(x); close(x); 3: char refdir[50]; 4: savedir() 5: { 6: int pipev[2]; 7: int status, n; 8: 9: if (refdir[0]==0) { 10: pipe (pipev); 11: if (fork()==0) 12: { 13: close (pipev[0]); 14: move (pipev[1], 1); 15: execl("/bin/pwd", "pwd", 0); 16: fprintf(stderr,"Can't run /bin/pwd"); 17: exit(1); 18: } 19: close(pipev[1]); 20: wait(&status); 21: if (status) 22: err("Can't run pwd"); 23: n = read (pipev[0], refdir, 49); 24: refdir[n]=0; 25: close(pipev[0]); 26: trimnl(refdir); 27: } 28: } 29: restodir() 30: { 31: chdir(refdir); 32: }