home: hub: zuo

Download patch

ref: dfe2721a76eddfc50fe3a2e8c80b63b522a4c182
parent: 9d12fe620913112fc81294c7df2b6322c8a5a8e1
author: Matthew Flatt <mflatt@racket-lang.org>
date: Thu Dec 1 10:04:06 CST 2022

make 'avail read mode return eof

This is a backward-incompatible change, but hopefully in a small
corner. It's more helpful to reporting eof for 'avail mode to
distinguish between an EOF being available and nothing being
immediately available.

--- a/tests/file-handle.zuo
+++ b/tests/file-handle.zuo
@@ -40,6 +40,7 @@
 (let ([in (fd-open-input (build-path tmp-dir "handle1.txt"))])
   (check (fd-read in eof) "one")
   (check (fd-read in 1) eof)
+  (check (fd-read in 'avail) eof)
   (check (fd-read in eof) "")
   (check (void? (fd-close in))))
 
--- a/zuo-doc/lang-zuo.scrbl
+++ b/zuo-doc/lang-zuo.scrbl
@@ -998,7 +998,7 @@
 that many bytes, @racket[eof] to read all content up to an
 end-of-file, or @racket['avail] where supported (on Unix) to read as
 many bytes as available in non-blocking mode. The result is
-@racket[eof] if @racket[amount] is not @racket[0], @racket[eof], or @racket['avail]
+@racket[eof] if @racket[amount] is not @racket[0] or @racket[eof]
 and if no bytes are available before an end-of-file; otherwise, it is a
 string containing the read bytes.
 
@@ -1005,7 +1005,9 @@
 The number of bytes in the returned string can be less than
 @racket[amount] if the number of currently available bytes is less
 than @racket[amount] but at least one byte. The result can be an empty
-string only if @racket[amount] is @racket[0] or @racket['avail].}
+string only if @racket[amount] is @racket[0] or @racket['avail].
+
+@history[#:changed "1.5" @elem{Report @racket[eof] when available in @racket['avail] mode.}]}
 
 @defproc[(fd-write [handle handle?] [str string?]) void?]{
 
--- a/zuo.c
+++ b/zuo.c
@@ -3,7 +3,7 @@
    declarations. */
 
 #define ZUO_VERSION 1
-#define ZUO_MINOR_VERSION 4
+#define ZUO_MINOR_VERSION 5
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
 # define ZUO_WINDOWS
@@ -4221,7 +4221,7 @@
   ZUO_STRING_PTR(s)[offset] = 0;
   ZUO_STRING_LEN(s) = offset;
 
-  if ((offset == 0) && (amount > 0))
+  if ((offset == 0) && ((amount > 0) || (amount == -2)))
     return z.o_eof;
 
   return s;