]>
diplodocus.org Git - nmh/blob - sbr/pwd.c
3 * pwd.c -- return the current working directory
10 static char curwd
[PATH_MAX
];
18 if (!getcwd (curwd
, PATH_MAX
)) {
19 admonish (NULL
, "unable to determine working directory");
20 if (!mypath
|| !*mypath
21 || (strcpy (curwd
, mypath
), chdir (curwd
)) == -1) {
28 if ((cp
= curwd
+ strlen (curwd
) - 1) > curwd
&& *cp
== '/')
38 * Currently commented out. Everyone seems
39 * to have a native version these days.
43 * getwd() - get the current working directory
50 char tmp1
[BUFSIZ
], tmp2
[BUFSIZ
];
51 struct stat st1
, st2
, root
;
52 register struct direct
*dp
;
59 if ((dd
= opendir ("..")) == NULL
)
61 if (stat (".", &st2
) == -1 || stat ("..", &st1
) == -1)
63 if (st2
.st_ino
== root
.st_ino
&& st2
.st_dev
== root
.st_dev
) {
68 if (st2
.st_ino
== st1
.st_ino
&& st2
.st_dev
== st1
.st_dev
) {
71 if ((dd
= opendir (".")) == NULL
)
73 if (stat (".", &st1
) < 0)
75 if (st2
.st_dev
!= st1
.st_dev
)
76 while (dp
= readdir (dd
)) {
77 if (stat (dp
->d_name
, &st1
) == -1)
79 if (st2
.st_dev
== st1
.st_dev
) {
80 snprintf (tmp1
, sizeof(tmp1
), "%s%s", dp
->d_name
, cwd
);
81 strcpy (cwd
+ 1, tmp1
);
93 while (dp
= readdir (dd
)) {
94 snprintf (tmp2
, sizeof(tmp2
), "../%s", dp
->d_name
);
95 if (stat (tmp2
, &st1
) != -1
96 && st1
.st_ino
== st2
.st_ino
97 && st1
.st_dev
== st2
.st_dev
) {
101 snprintf (tmp1
, sizeof(tmp1
), "%s%s", dp
->d_name
, cwd
);
102 strcpy (cwd
+ 1, tmp1
);