diff options
author | peter <peter@FreeBSD.org> | 1997-09-16 06:00:50 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-09-16 06:00:50 +0000 |
commit | d96eb92b4f98b9fd1ddf5feb196c628506966f3c (patch) | |
tree | ef17b1ca44a165a3fb6948f1306be8bb3b2132dd | |
parent | 93105e4a327cad4452d5b7fa3cd9614f5a70815a (diff) | |
download | FreeBSD-src-d96eb92b4f98b9fd1ddf5feb196c628506966f3c.zip FreeBSD-src-d96eb92b4f98b9fd1ddf5feb196c628506966f3c.tar.gz |
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.
-rw-r--r-- | lib/libc/gen/getcwd.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 38c911c..344a418 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -45,11 +45,14 @@ static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <signal.h> #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) +static int have__getcwd = 1; /* 0 = no, 1 = perhaps, 2 = yes */ + char * getcwd(pt, size) char *pt; @@ -89,17 +92,40 @@ getcwd(pt, size) return (NULL); ept = pt + ptsize; } - if (!__getcwd(pt, ept - pt)) { - if (*pt != '/') { - bpt = pt; - ept = pt + strlen(pt) - 1; - while (bpt < ept) { - c = *bpt; - *bpt++ = *ept; - *ept-- = c; + if (have__getcwd) { + struct sigaction sa, osa; + int sigsys_installed = 0; + int ret; + + if (have__getcwd == 1) { /* unsure? */ + bzero(&sa, sizeof(sa)); + sa.sa_handler = SIG_IGN; + if (sigaction(SIGSYS, &sa, &osa) >= 0) + sigsys_installed = 1; + } + ret = __getcwd(pt, ept - pt); + if (sigsys_installed == 1) { + int oerrno = errno; + sigaction(SIGSYS, &osa, NULL); + errno = oerrno; + } + /* XXX a bogus syscall seems to return EINVAL(!) */ + if (ret < 0 && (errno == ENOSYS || errno == EINVAL)) + have__getcwd = 0; + else if (have__getcwd == 1) + have__getcwd = 2; /* yep, remember we have it */ + if (ret == 0) { + if (*pt != '/') { + bpt = pt; + ept = pt + strlen(pt) - 1; + while (bpt < ept) { + c = *bpt; + *bpt++ = *ept; + *ept-- = c; + } } + return (pt); } - return (pt); } bpt = ept - 1; *bpt = '\0'; |