The saga of file-read pasted by Jubjub on Sun May 4 15:36:51 2014
Original file (102 bytes): (use awful) (enable-sxml #t) (define-page (main-page-path) (lambda () "Hello there!")) Testing file-read: CHICKEN (c) 2008-2014, The Chicken Team (c) 2000-2007, Felix L. Winkelmann Version 4.9.1 (rev b00d73a) windows-mingw32-x86 [ manyargs dload ptables ] compiled 2014-04-19 on Cairo (MINGW32_NT-6.1) #;1> (use posix) ; loading c:/MinGW//lib/chicken/7/posix.import.so ... ; loading library posix ... #;2> (define fileno (port->fileno (open-input-file "lobby.css"))) #;3> (define read (file-read fileno 95)) #;4> read ("(use awful)\n\n(enable-sxml #t)\n\n(define-page (main-page-path)\n (lambda () \n \"Hello thero ther" 89) #;5> (string-length (car read)) 95
no title pasted by andyjpb on Sun May 4 15:42:33 2014
$ uname -a Linux ridgewood 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux x.scm: ----- (use posix) (define fileno (port->fileno (open-input-file "lobby.css"))) (define read (file-read fileno 95)) (pp read) (pp (string-length (car read))) ----- $ /usr/local/chicken-4.7.0/bin/csi -ns x.scm ("(use awful)\n\n(enable-sxml #t)\n\n(define-page (main-page-path)\n (lambda ()\n \"Hello there!\"))\n" 95) 95 ----- $ /usr/local/chicken-4.9.0/bin/csi -ns x.scm Error: segmentation violation Call history: <syntax> (quote posix) <syntax> (##core#quote posix) <syntax> (import posix) <syntax> (##core#undefined) <syntax> (##core#undefined) <eval> (##sys#load-library (quote posix) #f) <syntax> (define fileno (port->fileno (open-input-file "lobby.css"))) <syntax> (##core#set! fileno (port->fileno (open-input-file "lobby.css"))) <syntax> (port->fileno (open-input-file "lobby.css")) <syntax> (open-input-file "lobby.css") <eval> (port->fileno (open-input-file "lobby.css")) <eval> (open-input-file "lobby.css") <syntax> (define read (file-read fileno 95)) <syntax> (##core#set! read (file-read fileno 95)) <syntax> (file-read fileno 95) <eval> (file-read fileno 95) <-- -----
use r instead of read pasted by andyjpb on Sun May 4 15:45:15 2014
$ /usr/local/chicken-4.9.0/bin/csc x.scm Warning: at toplevel: assignment of value of type `list' to toplevel variable `read' does not match declared type `(procedure read (#!optional input-port) *)' Warning: redefinition of standard binding: read y.scm: ----- (use posix) (define fileno (port->fileno (open-input-file "lobby.css"))) (define r (file-read fileno 95)) (pp r) (pp (string-length (car r))) ----- $ /usr/local/chicken-4.9.0/bin/csc x.scm $ /usr/local/chicken-4.9.0/bin/csi -ns x.scm ("(use awful)\n\n(enable-sxml #t)\n\n(define-page (main-page-path)\n (lambda ()\n \"Hello there!\"))\n" 95) 95
file-read solution added by Jubjub on Sun May 4 16:08:31 2014
Same behavior with file-open: CHICKEN (c) 2008-2014, The Chicken Team (c) 2000-2007, Felix L. Winkelmann Version 4.9.1 (rev a3c7a5a) windows-mingw32-x86 [ manyargs dload ptables ] compiled 2014-05-04 on Cairo (MINGW32_NT-6.1) #;1> (use posix) ; loading C:/MinGW//lib/chicken/7/posix.import.so ... ; loading library posix ... #;2> (define fd (file-open "lobby.css" open/read)) #;3> fd 3 #;4> (define r (file-read fd 95)) #;5> r ("(use awful)\n\n(enable-sxml #t)\n\n(define-page (main-page-path)\n (lambda () \n \"Hello thero ther" 89) However, if we add the binary flag: CHICKEN (c) 2008-2014, The Chicken Team (c) 2000-2007, Felix L. Winkelmann Version 4.9.1 (rev a3c7a5a) windows-mingw32-x86 [ manyargs dload ptables ] compiled 2014-05-04 on Cairo (MINGW32_NT-6.1) #;1> (use posix) ; loading C:/MinGW//lib/chicken/7/posix.import.so ... ; loading library posix ... #;2> (define fd (file-open "lobby.css" (+ open/read open/binary))) #;3> fd 3 #;4> (define r (file-read fd 95)) #;5> r ("(use awful)\r\n\r\n(enable-sxml #t)\r\n\r\n(define-page (main-page-path)\r\n (lambda ()\r\n \"Hello ther" 95)