Backed out Keith Bostic's getcwd/$PWD hack. It is causing things to break

all over the place.
This commit is contained in:
David Greenman 1995-02-07 05:52:57 +00:00
parent df76d2a332
commit 16be381004
2 changed files with 6 additions and 31 deletions

View File

@ -46,7 +46,7 @@
.Sh DESCRIPTION
The
.Fn getcwd
function copies an absolute pathname of the current working directory
function copies the absolute pathname of the current working directory
into the memory referenced by
.Fa buf
and returns a pointer to
@ -89,12 +89,6 @@ open the current directory
and use the
.Xr fchdir 2
function to return.
.Pp
These routines examine the the environment variable PWD,
if it is an absolute path for the current directory,
that path will be returned.
Consequently, if the ``canonical'' name of the current directory is
needed, unset the PWD environment variable before calling these routines.
.Sh RETURN VALUES
Upon successful completion, a pointer to the pathname is returned.
Otherwise a

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1989, 1991, 1993, 1995
* Copyright (c) 1989, 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getcwd.c 8.2 (Berkeley) 1/31/95";
static char sccsid[] = "@(#)getcwd.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@ -63,29 +63,10 @@ getcwd(pt, size)
struct stat s;
dev_t root_dev;
ino_t root_ino;
size_t ptsize, pwdlen, upsize;
size_t ptsize, upsize;
int save_errno;
char *ept, *eup, *pwd, *up;
char *ept, *eup, *up;
/* Check $PWD -- if it's right, it's fast. */
if ((pwd = getenv("PWD")) != NULL && !stat(pwd, &s) && *pwd == '/') {
dev = s.st_dev;
ino = s.st_ino;
if (!stat(".", &s) && dev == s.st_dev && ino == s.st_ino) {
pwdlen = strlen(pwd);
if (size != 0) {
if (pwdlen + 1 > size) {
errno = ERANGE;
return (NULL);
}
} else if ((pt = malloc(pwdlen + 1)) == NULL)
return (NULL);
memmove(pt, pwd, pwdlen);
pwd[pwdlen] = '\0';
return (pt);
}
}
/*
* If no buffer specified by the user, allocate one as necessary.
* If a buffer is specified, the size has to be non-zero. The path
@ -113,7 +94,7 @@ getcwd(pt, size)
/*
* Allocate bytes (1024 - malloc space) for the string of "../"'s.
* Should always be enough (it's 340 levels). If it's not, allocate
* as necessary. Special case the first stat, it's ".", not "..".
* as necessary. Special * case the first stat, it's ".", not "..".
*/
if ((up = malloc(upsize = 1024 - 4)) == NULL)
goto err;