* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)getcwd.c 5.4 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
register struct dirent
*dp
;
char path
[MAXPATHLEN
], up
[MAXPATHLEN
], *strerror();
pp
= path
+ sizeof(path
) - 1;
for (pu
= up
, first
= 1;; first
= 0) {
if (root_dev
== s
.st_dev
&& root_ino
== s
.st_ino
) {
(void)strcpy(store
+ 1, pp
);
if (!(dir
= opendir(up
))) {
(void)strcpy(path
, "getwd: opendir failed.");
while (dp
= readdir(dir
)) {
if (dp
->d_name
[0] == '.' && (!dp
->d_name
[1] ||
dp
->d_name
[1] == '.' && !dp
->d_name
[2]))
bcopy(dp
->d_name
, pu
, dp
->d_namlen
+ 1);
if (tmp
.st_dev
== s
.st_dev
&& tmp
.st_ino
== s
.st_ino
) {
bcopy(dp
->d_name
, pp
, dp
->d_namlen
);
err
: (void)sprintf(path
, "getwd: %s", strerror(errno
));