Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de9775a

Browse files
committed
Initial revision
1 parent 28a83ab commit de9775a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Python/getcwd.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Quick hack to get posix.getcwd() working for pure BSD 4.3 */
2+
3+
#include "sys/param.h"
4+
#include "errno.h"
5+
6+
extern int errno;
7+
8+
extern char *getwd();
9+
10+
char *
11+
getcwd(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 ... */

0 commit comments

Comments
 (0)