Commit Graph

16 Commits

Author SHA1 Message Date
John Birrell
efda37108b NetBSD doesn't have a __getcwd syscall, so set have__getcwd to `no'
when building libc with NetBSD syscalls.
1998-05-15 11:59:00 +00:00
Stephen McKay
4773010d2f 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.
1998-01-15 13:52:55 +00:00
Peter Wemm
b7ecb08afa 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.
1997-09-16 06:00:50 +00:00
Poul-Henning Kamp
36dff60096 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.
1997-09-15 17:40:15 +00:00
Poul-Henning Kamp
9c2d6fcf05 Fix a buglet and a couple of stylistic nits from Bruce. 1997-09-15 08:25:14 +00:00
Poul-Henning Kamp
27262cac33 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.
1997-09-14 16:57:27 +00:00
David Greenman
f5f31fba12 Fixed file descriptor leak that occurs after certain types of failures.
PR:		3516
Submitted by:	Matthew Flatt <mflatt@cs.rice.edu>
1997-08-15 05:21:16 +00:00
Peter Wemm
098f04f5d1 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
1997-03-13 06:45:38 +00:00
Peter Wemm
9dc1164189 merge from Lite2 - realpath() now shares a lot of code with getcwd()
and is now in the same file.
1997-03-11 11:37:59 +00:00
Peter Wemm
0d4453d303 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
1996-10-17 00:40:04 +00:00
Jordan K. Hubbard
51295a4d3e General -Wall warning cleanup, part I.
Submitted-By: Kent Vander Velden <graphix@iastate.edu>
1996-07-12 18:57:58 +00:00
Jeffrey Hsu
e78bad2371 Don't cast void functions to void.
Obtained from: NetBSD commit by jtc on June 16, 1995.
1995-06-20 18:31:16 +00:00
David Greenman
16be381004 Backed out Keith Bostic's getcwd/$PWD hack. It is causing things to break
all over the place.
1995-02-07 05:52:57 +00:00
Poul-Henning Kamp
03cfe806a2 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)
1995-02-04 19:29:22 +00:00
Bruce Evans
b01f0b7d76 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);
}
1994-12-12 01:29:13 +00:00
Rodney W. Grimes
58f0484fa2 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00