Welcome to the CHICKEN Scheme pasting service
FFI code libssh added by zilti on Mon Nov 14 20:07:26 2016
(define (ssh-read channel buf) @("Low-level interface to read from an ssh channel." (channel "The ssh channel to read from.") (buf "An s8vector to read the data into.") (@to "A cons cell with car being the amount of bytes left and cdr being buf.")) (let ((nbytes ($ int ssh_channel_read (c-pointer channel) (s8vector buf) (int (s8vector-length buf)) 0))) (cons nbytes buf))) (define (read-response channel bufsize accumulation) (let* ((buf (make-s8vector bufsize 0)) (response (ssh-read channel buf)) (bufsize (if (> 256 (car response)) (car response) 256)) (accumulation (cons (s8vector->byte-blob (cdr response)) accumulation))) ;; (release-number-vector buf) (if (> (car response) 0) (read-response channel bufsize accumulation) (flatten accumulation)))) (define (ssh-read-all channel) @("Reads all remaining data from the given ssh channel. UTF-8-aware." (channel "The channel to read from.") (@to "A properly formatted string.")) (let* ((accumulation (read-response channel 256 '())) (result (byte-blob->string (fold (lambda (input acc) (byte-blob-append input acc)) (byte-blob-empty) accumulation)))) result))