$NetBSD$

--- esdlib.c.orig	2008-07-30 16:09:38.000000000 +0200
+++ esdlib.c
@@ -149,6 +149,13 @@ write_timeout (int fd, const char *buf, 
 		do {
 			n = write (fd, buf + nwritten, buflen - nwritten);
 		} while (n == -1 && errno == EINTR);
+
+		if (n == -1) {
+			rv = errno;
+			fcntl (fd, F_SETFL, flags);
+			errno = rv;
+			return -1;
+		}
 		
 		if (n > 0)
 			nwritten += n;
