diff Python/getcwd.c @ 116:0a02ca9dcd6e legacy-trunk

Initial revision
author Guido van Rossum <guido@python.org>
date Mon, 21 Jan 1991 14:27:52 +0000
parents
children c70eefe48029
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Python/getcwd.c	Mon Jan 21 14:27:52 1991 +0000
@@ -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 ... */