Guido van Rossum | de9775a | 1991-01-21 14:27:52 +0000 | [diff] [blame^] | 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 ... */ |