From 6a4f3d0fd940c1e7052ddf23907f0e297dc42f4b Mon Sep 17 00:00:00 2001 From: etheisen Date: Sat, 14 Sep 1996 19:02:02 +0000 Subject: Third time because import sucks. --- gnu/usr.bin/groff/libgroff/getcwd.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 gnu/usr.bin/groff/libgroff/getcwd.c (limited to 'gnu/usr.bin/groff/libgroff/getcwd.c') diff --git a/gnu/usr.bin/groff/libgroff/getcwd.c b/gnu/usr.bin/groff/libgroff/getcwd.c new file mode 100644 index 00000000000..208e8111853 --- /dev/null +++ b/gnu/usr.bin/groff/libgroff/getcwd.c @@ -0,0 +1,38 @@ +/* Partial emulation of getcwd in terms of getwd. */ + +#include +#include +#include +#ifndef errno +extern int errno; +#endif + +char *getwd(); + +char *getcwd(buf, size) + char *buf; + int size; /* POSIX says this should be size_t */ +{ + if (size <= 0) { + errno = EINVAL; + return 0; + } + else { + char mybuf[MAXPATHLEN]; + int saved_errno = errno; + + errno = 0; + if (!getwd(mybuf)) { + if (errno == 0) + ; /* what to do? */ + return 0; + } + errno = saved_errno; + if (strlen(mybuf) + 1 > size) { + errno = ERANGE; + return 0; + } + strcpy(buf, mybuf); + return buf; + } +} -- cgit v1.2.3