blob: 340acabf898e708cdbc746d1bc21428bb8db28ed [file] [log] [blame]
Guido van Rossumde9775a1991-01-21 14:27:52 +00001/* Quick hack to get posix.getcwd() working for pure BSD 4.3 */
2
3#include "sys/param.h"
4#include "errno.h"
5
6extern int errno;
7
8extern char *getwd();
9
10char *
11getcwd(buf, size)
12 char *buf;
13 int size;
14{
15 char localbuf[MAXPATHLEN+1];
16 char *ret;
17
18 if (size <= 0) {
19 errno = EINVAL;
20 return NULL;
21 }
22 ret = getwd(localbuf);
23 if (ret != NULL && strlen(localbuf) >= size) {
24 errno = ERANGE;
25 return NULL;
26 }
27 if (ret == NULL) {
28 errno = EACCES; /* Most likely error */
29 return NULL;
30 }
31 strncpy(buf, localbuf, size);
32 return buf;
33}
34
35/* PS: for really old systems you must popen /bin/pwd ... */