064-file-append.scm (669B)
1 ; Pin open-output (truncating) vs open-append (preserving + appending). 2 ; Write "hello\n" with open-output, then "world\n" with open-append, and 3 ; verify the file contains the concatenation. 4 (define path "/tmp/scheme1-append.txt") 5 6 (define o1 (open-output path)) 7 (if (not (car o1)) (exit 10) 0) 8 (write-bytes (cdr o1) "hello\n") 9 (close (cdr o1)) 10 11 (define o2 (open-append path)) 12 (if (not (car o2)) (exit 20) 0) 13 (write-bytes (cdr o2) "world\n") 14 (close (cdr o2)) 15 16 (define ip (open-input path)) 17 (if (not (car ip)) (exit 30) 0) 18 (define rd (read-all (cdr ip))) 19 (close (cdr ip)) 20 (if (not (car rd)) (exit 40) 0) 21 22 (if (bytevector=? (cdr rd) "hello\nworld\n") (exit 0) (exit 50))