1: /*
2: * Getwd
3: */
4: #include <stdio.h>
5: #include <sys/param.h>
6: #include <sys/stat.h>
7: #include <sys/dir.h>
8:
9: char dot[] = ".";
10: char dotdot[] = "..";
11: DIR *file;
12: int off = -1;
13: struct stat d, dd;
14: struct direct *dir;
15:
16: getwd(name)
17: char *name;
18: {
19: int rdev, rino;
20:
21: name[0] = '/';
22: stat("/", &d);
23: rdev = d.st_dev;
24: rino = d.st_ino;
25: for (;;) {
26: stat(dot, &d);
27: if (d.st_ino==rino && d.st_dev==rdev) {
28: return;
29: }
30: if ((file = opendir(dotdot)) == NULL) {
31: error ("can't open ..");
32: }
33: fstat(file->dd_fd, &dd);
34: chdir(dotdot);
35: if(d.st_dev == dd.st_dev) {
36: if(d.st_ino == dd.st_ino){
37: return;
38: }
39: do
40: if ((dir = readdir(file)) == NULL) {
41: fprintf(stderr,"read error in ..\n");
42: exit(1);
43: }
44: while (dir->d_ino != d.st_ino);
45: } else
46: do {
47: if ((dir = readdir(file)) == NULL) {
48: fprintf(stderr,"read error in ..\n");
49: exit(1);
50: }
51: stat(dir->d_name, &dd);
52: } while(dd.st_ino != d.st_ino || dd.st_dev != d.st_dev);
53: closedir(file);
54: cat(name+1);
55: }
56: }
57:
58: cat(name)
59: char *name;
60: {
61: register i, j;
62:
63: i = dir->d_namlen;
64: for(j=off+1; j>=0; --j)
65: name[j+i+1] = name[j];
66: off=i+off+1;
67: name[i] = '/';
68: for(--i; i>=0; --i)
69: name[i] = dir->d_name[i];
70: }
Defined functions
cat
defined in line
58; used 1 times
getwd
defined in line
16; used 1 times
Defined variables
d
defined in line
13; used 11 times
dd
defined in line
13; used 6 times
dir
defined in line
14; used 6 times
dot
defined in line
9; used 1 times
off
defined in line
12; used 3 times