9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.01.31.21.56.45; author jromine; state Exp;
19 date 90.04.05.15.30.25; author sources; state Exp;
24 date 90.04.05.14.44.11; author sources; state Exp;
29 date 90.02.05.14.38.27; author sources; state Exp;
34 date 89.11.17.15.57.25; author sources; state Exp;
39 date 89.06.26.14.31.50; author sources; state Exp;
53 @/* pwd.c - return the current working directory */
55 static char ident[] = "@@(#)$Id: pwd.c,v 2.4 1992/01/31 21:56:45 jromine Exp jromine $";
59 #if !defined (BSD42) && !defined (SYS5DIR)
60 #include "../h/local.h"
61 #endif /* not BSD42 and not SYS5DIR */
64 #define MAXPATHLEN 1024
66 static char curwd[MAXPATHLEN];
75 if (getwd (curwd) == NOTOK) {
76 admonish (NULL, "unable to determine working directory");
78 if (getcwd (curwd, MAXPATHLEN) == NULL) {
79 admonish (NULL, "unable to determine working directory");
82 if (getwd (curwd) == 0) {
83 admonish (NULLCP, "unable to determine working directory: %s", curwd);
87 || ((void) strcpy (curwd, mypath), chdir (curwd)) == NOTOK) {
88 (void) strcpy (curwd, "/");
94 if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/')
102 #if !defined (BSD42) && !defined (SYS5DIR)
103 /* getwd() - get the current working directory */
105 /* Algorithm from several sources, -ljobs, pwd.c, etc., etc. */
116 register struct direct *dp;
119 (void) strcpy (cwd, "/");
120 (void) stat ("/", &root);
123 if ((dd = opendir ("..")) == NULL)
125 if (stat (".", &st2) == NOTOK || stat ("..", &st1) == NOTOK)
127 if (st2.st_ino == root.st_ino && st2.st_dev == root.st_dev) {
132 if (st2.st_ino == st1.st_ino && st2.st_dev == st1.st_dev) {
135 if ((dd = opendir (".")) == NULL)
137 if (stat (".", &st1) < 0)
139 if (st2.st_dev != st1.st_dev)
140 while (dp = readdir (dd)) {
141 if (stat (dp -> d_name, &st1) == NOTOK)
143 if (st2.st_dev == st1.st_dev) {
144 (void) sprintf (tmp1, "%s%s", dp -> d_name, cwd);
145 (void) strcpy (cwd + 1, tmp1);
147 return (chdir (cwd));
152 return (chdir (cwd));
157 while (dp = readdir (dd)) {
158 (void) sprintf (tmp2, "../%s", dp -> d_name);
159 if (stat (tmp2, &st1) != NOTOK
160 && st1.st_ino == st2.st_ino
161 && st1.st_dev == st2.st_dev) {
165 (void) sprintf (tmp1, "%s%s", dp -> d_name, cwd);
166 (void) strcpy (cwd + 1, tmp1);
178 #endif /* not BSD42 and not SYS5DIR */
189 static char ident[] = "@@(#)$Id: pwd.c,v 2.3 1990/04/05 15:30:25 sources Exp jromine $";
193 #endif not BSD42 and not SYS5DIR
206 #endif not BSD42 and not SYS5DIR
217 static char ident[] = "@@(#)$Id:$";
220 if (getwd (curwd) == NULL) {
237 static char ident[] = "$Id:";
252 @changes for SUN40 shared libraries and NNTP under bbc
268 register struct dirent *dp;