boot2

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

063-file-output-roundtrip.scm (665B)


      1 ; open-output -> write-bytes -> close -> open-input -> read-all roundtrip.
      2 ; Pins both halves of the prelude port API (write side + read side) and
      3 ; the open-output/MODE_644/O_TRUNC flag combination via the public
      4 ; surface only.
      5 (define path "/tmp/scheme1-output-roundtrip.txt")
      6 (define payload "abc\nxyz")
      7 
      8 (define op (open-output path))
      9 (if (not (car op)) (exit 10) 0)
     10 (define wr (write-bytes (cdr op) payload))
     11 (close (cdr op))
     12 (if (not (car wr)) (exit 20) 0)
     13 
     14 (define ip (open-input path))
     15 (if (not (car ip)) (exit 30) 0)
     16 (define rd (read-all (cdr ip)))
     17 (close (cdr ip))
     18 (if (not (car rd)) (exit 40) 0)
     19 
     20 (if (bytevector=? (cdr rd) payload) (exit 0) (exit 50))