1: # 2: /* Curdir finds the name of the working directory and puts in 3: wdname. This is done by calling on the pwd program. 4: */ 5: #include "hd.h" 6: #include "mydir.h" 7: static char pwd[] = {"/bin/pwd"}; 8: 9: curdir () { 10: 11: int p, rdlen, pipefile [2]; 12: #define pipein pipefile [0] 13: #define pipeout pipefile [1] 14: 15: pipe (pipefile); 16: printf ("%s\n", pwd); 17: if ((p = myfork ()) == 0) { 18: close (outfile); dup (pipeout); 19: close (pipein); close (pipeout); 20: execl (pwd, pwd, 0); 21: exit (1); 22: } else { 23: close (pipeout); 24: join (p); 25: rdlen = read (pipein, wdname, sizeof wdname); 26: if (rdlen < 2 || rdlen == sizeof wdname || wdname [0] != '/') { 27: printf ("Cannot find name of working directory\n\r"); 28: return 1; 29: } 30: wdname [rdlen - 1] = 0; 31: close (pipein); 32: } 33: return 0; 34: }