summaryrefslogtreecommitdiffstats
path: root/Python/getcwd.c
blob: 340acabf898e708cdbc746d1bc21428bb8db28ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 ... */