A better patch that stats the opened file. That avoids possible race conditions and is faster. thx to jonathan and NotFound for pointing the shortcomings of the previous patch.
# now the test pass ok 3 - slurp() on directories fails --- ./src/io/io_unix.c.orig 2008-09-19 17:56:19.000000000 +0200 +++ ./src/io/io_unix.c 2008-09-19 19:16:04.000000000 +0200 @@ -353,6 +353,14 @@ } if (fd >= 0) { + struct stat buf; + if (fstat(fd, &buf) == -1) + return NULL; + if ((buf.st_mode & S_IFMT) == S_IFDIR) { + errno = EISDIR; + return NULL; + } + /* Set generic flag here if is a terminal then * higher layers can know how to setup buffering. * STDIN, STDOUT, STDERR would be in this case