read-symbolic-link crash added by gahr on Mon Oct 28 15:31:34 2024

> cat read-symbolic-link.scm
(import (chicken foreign)
        (chicken fixnum)
        (chicken file posix)
        )

(define-foreign-variable _filename_max long "FILENAME_MAX")

#>
#define C_do_readlink(f, b) C_fix(readlink(C_c_string(f), C_c_string(b), FILENAME_MAX))
<#

(define buf (make-string (fx+ _filename_max 1) #\a))
(let ((res (##core#inline "C_do_readlink" (##sys#make-c-string "/home" 'here) buf)))
  (print "buf: <" buf ">")
  (print "res: <" res ">")
  (substring buf 0 res))

> csc read-symbolic-link.scm

> ./read-symbolic-link

Error: bus error

        Call history:

        read-symbolic-link.scm:12: scheme#make-string     
        read-symbolic-link.scm:13: ##sys#make-c-string    
        read-symbolic-link.scm:14: chicken.base#print           <--
buf: <