History log of /freebsd-10.1-release/lib/libc/gen/getcwd.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 241046 29-Sep-2012 jilles

libc: Use O_CLOEXEC for various internal file descriptors.

This fixes a race condition where another thread may fork() before CLOEXEC
is set, unintentionally passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still
leaves a race window so it should be fixed later.


# 235647 19-May-2012 gleb

Hide DIR definition by making it an opaque struct typedef.

Introduce dirfd() libc exported symbol replacing macro with same name,
preserve _dirfd() macro for internal use.

Replace dirp->dd_fd with dirfd() call. Avoid using dirfd as variable
name to prevent shadowing global symbol.

Sponsored by: Google Summer Of Code 2011


# 198053 13-Oct-2009 jilles

Make getcwd(3) faster, simpler and more compliant using *at syscalls.

It is no longer necessary to construct long paths consisting of repeated
"../" which may be slow to process and may exceed PATH_MAX.


# 165903 08-Jan-2007 imp

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# 150297 18-Sep-2005 ache

Just by allocating size*2 bytes we can't be sure that new size will be enough,
so change two
if (size not enough) {
reallocf(size*2);
}
into
while (size not enough) {
reallocf(size*2);
}


# 150172 15-Sep-2005 ache

Cosmetic fixes to prev. commit.
Change first MAXPATHLEN to more standard PATH_MAX
Change second MAXPATHLEN to 1024 (it is temp buffer not related)
Change comment to reflect that.

Suggested by: bde


# 150138 14-Sep-2005 ache

Remove any hardcoded assumptions about malloc's way of allocating,
just use MAXPATHLEN. It prevents potential buffer overflow with other
malloc implementations.
(this change based on submitted patch)

PR: 86135
Submitted by: Trevor Blackwell <tlb@tlb.org>


# 121667 29-Oct-2003 tjr

Remove incomplete support for running FreeBSD userland on old NetBSD kernels
lacking the issetugid() and utrace() syscalls.


# 109040 10-Jan-2003 tjr

Avoid a memory leak by using reallocf() instead of realloc().


# 109039 10-Jan-2003 tjr

Prototype __getcwd() to avoid a warning.


# 102117 19-Aug-2002 jmallett

s/trailing NULL/trailing NUL/


# 90041 31-Jan-2002 obrien

* Remove 'register'. (some functions had 7+ register functions...)
* Fix SCM ID's.


# 71579 24-Jan-2001 deischen

Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by: -arch


# 65468 05-Sep-2000 peter

Remove the SIGSYS handler and wrapper around the __getcwd() syscall.
It was kinda silly since the sigaction() syscall that it used to setup
the handler is more recent than __getcwd(), therefore it was useless
as the wrapper would have died before even getting as far as __getcwd(2).

Reminded by: bde


# 51758 28-Sep-1999 marcel

Explicitly use sigemptyset to clear a sigset_t. Explicit
initialization of sa_flags allows us to lose the bzero.

$FreeBSD$ tag added.


# 39327 16-Sep-1998 imp

Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a =
realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is
guaranteed to be the same thing.

I've been running these on my system here w/o ill effects for some
time. However, the CTM-express is at part 6 of 34 for the CAM
changes, so I've not been able to do a build world with the CAM in the
tree with these changes. Shouldn't impact anything, but...


# 36060 15-May-1998 jb

NetBSD doesn't have a __getcwd syscall, so set have__getcwd to `no'
when building libc with NetBSD syscalls.


# 32530 15-Jan-1998 mckay

Return the correct errno from getcwd() even if free() or closedir()
overwrites it. This actually showed up when running under an old
kernel when free() called the madvise() stub which set errno, causing
getcwd() to return EOPNOTSUPP instead of ERANGE.


# 29487 16-Sep-1997 peter

Put a system call not present checking wrapper around the call to
__getcwd(). I've got this libc code running on one of my machines
at the moment without the __getcwd() syscall being present.


# 29476 15-Sep-1997 phk

Fix yet a minor stylistic nit from Bruce (Doesn't he have more
important things to do ?? :-)

Prepare for the likely case of a change in kernel algorithm.


# 29462 15-Sep-1997 phk

Fix a buglet and a couple of stylistic nits from Bruce.


# 29392 14-Sep-1997 phk

Add __getcwd() syscall, and have getcwd() take a shot at it.
If your kernel doesn't support __getcwd() or if __getcwd() cannot
deliver because of cache expiry, it does the canonical thing.


# 28235 15-Aug-1997 dg

Fixed file descriptor leak that occurs after certain types of failures.

PR: 3516
Submitted by: Matthew Flatt <mflatt@cs.rice.edu>


# 23832 13-Mar-1997 peter

Back out a dubious Lite2 change to "optimise" getcwd() to look at $PWD
because it's potentially dangerous (think: symlink races). Move
realpath() back to it's original location, and remove getcwd_physical()
by renaming it back to getcwd() and zapping the original getcwd wrapper.

Noticed by: bde


# 23661 11-Mar-1997 peter

merge from Lite2 - realpath() now shares a lot of code with getcwd()
and is now in the same file.


# 18971 16-Oct-1996 peter

Corrently null-terminate the path being passed to the opendir() calls,
malloc() does is not defined to return a zeroed buffer leading to
"strange" problems.

Submitted by: Karl Denninger <karl@mcs.com>, PR#1826


# 17141 12-Jul-1996 jkh

General -Wall warning cleanup, part I.
Submitted-By: Kent Vander Velden <graphix@iastate.edu>


# 9272 20-Jun-1995 hsu

Don't cast void functions to void.
Obtained from: NetBSD commit by jtc on June 16, 1995.


# 6227 07-Feb-1995 dg

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


# 6182 04-Feb-1995 phk

A cute hack to speed up things by Keith: if getenv("PWD") is the same
inode as ".", then just return that. I added a check so it must start with
a '/'.

Reviewed by: phk
Submitted by: bostic@cs.berkeley.edu (Keith Bostic)


# 5072 11-Dec-1994 bde

Obtained from: 1.1.5

getcwd() has two off-by-one bugs in FreeBSD-2.0:

1. getcwd(buf, size) fails when the size is just large enough.
2. getcwd(buf + 1, 1) incorrectly succeeds when the current directory
is "/". buf[0] and buf[2] are clobbered.

(I modified Bruce's original patch to return the proper error code
[ERANGE] in the case of #2, but otherwise... -DG)

This program demonstrates the bug:

---
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main(void)
{
char buf[5];
int errors;

errors = 0;
if (chdir("/tmp") != 0) {
perror("chdir");
abort();
}
if (getcwd(buf, 5) == NULL) {
perror("oops, getcwd failed for buffer size = size required");
++errors;
}
if (chdir("/") != 0) {
perror("chdir");
abort();
}
buf[0] = 0;
buf[2] = 1;
if (getcwd(buf + 1, 1) != NULL) {
fprintf(stderr,
"oops, getcwd succeeded for buffer size = one too small\n");
++errors;
}
if (buf[0] != 0) {
fprintf(stderr,
"oops, getcwd scribbled on memory before start of buffer\n");
++errors;
}
if (buf[2] != 1) {
fprintf(stderr,
"oops, getcwd scribbled on memory after end of buffer\n");
++errors;
}
exit(errors == 0 ? 0 : 1);
}


# 1574 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1573,
which included commits to RCS files with non-trunk default branches.


# 1573 27-May-1994 rgrimes

BSD 4.4 Lite Lib Sources