From de9775af8fc6f2e976f3815f00a5f389c777a91f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 21 Jan 1991 14:27:52 +0000 Subject: Initial revision --- Python/getcwd.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Python/getcwd.c diff --git a/Python/getcwd.c b/Python/getcwd.c new file mode 100644 index 0000000..340acab --- /dev/null +++ b/Python/getcwd.c @@ -0,0 +1,35 @@ +/* Quick hack to get posix.getcwd() working for pure BSD 4.3 */ + +#include "sys/param.h" +#include "errno.h" + +extern int errno; + +extern char *getwd(); + +char * +getcwd(buf, size) + char *buf; + int size; +{ + char localbuf[MAXPATHLEN+1]; + char *ret; + + if (size <= 0) { + errno = EINVAL; + return NULL; + } + ret = getwd(localbuf); + if (ret != NULL && strlen(localbuf) >= size) { + errno = ERANGE; + return NULL; + } + if (ret == NULL) { + errno = EACCES; /* Most likely error */ + return NULL; + } + strncpy(buf, localbuf, size); + return buf; +} + +/* PS: for really old systems you must popen /bin/pwd ... */ -- cgit v0.12