diff options
author | etheisen <etheisen@cvs.openbsd.org> | 1996-09-14 19:02:02 +0000 |
---|---|---|
committer | etheisen <etheisen@cvs.openbsd.org> | 1996-09-14 19:02:02 +0000 |
commit | 6a4f3d0fd940c1e7052ddf23907f0e297dc42f4b (patch) | |
tree | 712fd665d6b150ef04906975a7493d87d38a1a8a /gnu/usr.bin/groff/libgroff/getcwd.c | |
parent | 9cf27152dae9dbf80b167732c78c47baee90ddc5 (diff) |
Third time because import sucks.
Diffstat (limited to 'gnu/usr.bin/groff/libgroff/getcwd.c')
-rw-r--r-- | gnu/usr.bin/groff/libgroff/getcwd.c | 38 |
1 files changed, 38 insertions, 0 deletions
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 <sys/param.h> +#include <string.h> +#include <errno.h> +#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; + } +} |