1: /* Fortran get working directory. PLWard 3/20/80 */
2: /*
3: * Fortran callable character function to get working directory
4: * as a string. PLWard, USGS, Menlo Park, California
5: * Modified version of pwd.c.
6: */
7: #include <stdio.h>
8: #include <sys/param.h>
9: #include <sys/stat.h>
10: #include <sys/dir.h>
11:
12: char dot[] = ".";
13: char dotdot[] = "..";
14: int file;
15: struct stat d, dd;
16: struct direct dir;
17:
18: char workdr_(name,lim)
19: char name[];
20: long lim;
21: {
22: int rdev, rino;
23: register i, j;
24: int off;
25:
26: off = -1;
27: for(j=0;j<lim;j++) name[j]=' ';
28: stat("/", &d);
29: rdev = d.st_dev;
30: rino = d.st_ino;
31: for (;;) {
32: stat(dot, &d);
33: if (d.st_ino==rino && d.st_dev==rdev)
34: goto out;
35: if ((file = open(dotdot,0)) < 0) {
36: fprintf(stderr,"workdr: cannot open ..\n");
37: return;
38: }
39: fstat(file, &dd);
40: chdir(dotdot);
41: if(d.st_dev == dd.st_dev) {
42: if(d.st_ino == dd.st_ino)
43: goto out;
44: do
45: if (read(file, (char *)&dir, sizeof(dir)) < sizeof(dir)) {
46: fprintf(stderr,"workdr: read error in ..\n");
47: return;
48: }
49: while (dir.d_ino != d.st_ino);
50: }
51: else do {
52: if(read(file, (char *)&dir, sizeof(dir)) < sizeof(dir)) {
53: fprintf(stderr,"workdr: read error in ..\n");
54: return;
55: }
56: stat(dir.d_name, &dd);
57: } while(dd.st_ino != d.st_ino || dd.st_dev != d.st_dev);
58: close(file);
59: i = -1;
60: while (dir.d_name[++i] != 0);
61: if ((off+i+2) >= lim){
62: name[off]='\0';
63: i=chdir(dir.d_name);
64: j=chdir(name);
65: if(i!=0 | j!=0) fprintf(stderr,"workdr: unable to change back to working dir\n");
66: for(j=0;j<lim;j++)name[j]=' ';
67: return;
68: }
69: for(j=off+1; j>=0; --j)
70: name[j+i+1] = name[j];
71: off=i+off+1;
72: name[i] = '/';
73: for(--i; i>=0; --i)
74: name[i] = dir.d_name[i];
75: }
76: out:for(j=off+1; j>=0; --j)
77: name[j+1] = name[j];
78: name[0]='/';
79: if (off<0)
80: off = 0;
81: off=off+1;
82: name[off] = '\0';
83: chdir(name);
84: name[off] = ' ';
85: }
Defined functions
Defined variables
d
defined in line
15; used 11 times
dd
defined in line
15; used 6 times
dir
defined in line
16; used 11 times
dot
defined in line
12; used 1 times
file
defined in line
14; used 41 times
- in line 35-39(2),
45,
52,
58
- in /usr/src/cmd/file.c line
72-73(2),
86-94(4),
102,
132-135(2),
209
- in /usr/src/cmd/pwd.c line
29-33(2),
42,
49,
55
- in /usr/src/cmd/uucp/syskludge/creat.c line
5-10(3)
- in /usr/src/lib/c/gen/getwd.c line
33,
47,
55-64(4),
71-72(2),
78
- in /usr/src/sys/GENERIC/param.c line
104
- in /usr/src/sys/conf/param.c line
104
- in /usr/src/sys/dev/Others/mx2.c line
158,
173
- in /usr/src/sys/sys/fio.c line
121-126(2),
334-338(2)
- in /usr/src/sys/sys/syslocal.c line
406