Index: uspace/lib/posix/unistd.c
===================================================================
--- uspace/lib/posix/unistd.c	(revision 955c2b0051040bfbd062e5c3d182ad78cff2ed77)
+++ uspace/lib/posix/unistd.c	(revision e1065991b861fbf7f0d4f9b2eae2bf5312d00ea8)
@@ -110,9 +110,22 @@
 		return NULL;
 	}
+	
+	/* Save the original value to comply with the "no modification on
+	 * success" semantics.
+	 */
+	int orig_errno = errno;
+	errno = EOK;
+	
 	char *ret = getcwd(buf, size);
-	/* Check errno to avoid shadowing possible ENOMEM. */
-	if (ret == NULL && errno == EOK) {
-		errno = ERANGE;
-	}
+	if (ret == NULL) {
+		/* Check errno to avoid shadowing other possible errors. */
+		if (errno == EOK) {
+			errno = ERANGE;
+		}
+	} else {
+		/* Success, restore previous errno value. */
+		errno = orig_errno;
+	}
+	
 	return ret;
 }
