boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

012-slurp-fd.scm (707B)


      1 ;; tests/cc-util/12-slurp-fd.scm — slurp-fd reads to EOF and produces a
      2 ;; single bv that round-trips with write-bv-fd.
      3 ;; Assumes cc/util.scm is loaded.
      4 
      5 ;; Use the prelude's open-output / open-input to grab fds, then exercise
      6 ;; util.scm's fd-level helpers directly.
      7 (define payload "the quick brown fox jumps over the lazy dog\n")
      8 
      9 (define op-r (open-output "/tmp/cc-util-12.txt"))
     10 (if (car op-r) 0 (sys-exit 50))
     11 (define wfd (port-fd (cdr op-r)))
     12 (write-bv-fd wfd payload)
     13 (sys-close wfd)
     14 
     15 (define ip-r (open-input "/tmp/cc-util-12.txt"))
     16 (if (car ip-r) 0 (sys-exit 51))
     17 (define rfd (port-fd (cdr ip-r)))
     18 (define got (slurp-fd rfd))
     19 (sys-close rfd)
     20 
     21 (if (bv= got payload) 0 (sys-exit 1))
     22 (sys-exit 0)