gpgscm,w32: Provide schemish file handling for binary files.
authorJustus Winter <justus@g10code.com>
Mon, 7 Nov 2016 12:12:01 +0000 (13:12 +0100)
committerJustus Winter <justus@g10code.com>
Mon, 7 Nov 2016 12:13:31 +0000 (13:13 +0100)
* tests/gpgscm/lib.scm (call-with-binary-input-file): New function.
(call-with-binary-output-file): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/gpgscm/lib.scm

index 270189d..a8ae2f8 100644 (file)
        (loop acc))))))
 
 ;;
+;; Windows support.
+;;
+
+;; Like call-with-input-file but opens the file in 'binary' mode.
+(define (call-with-binary-input-file filename proc)
+  (letfd ((fd (open filename (logior O_RDONLY O_BINARY))))
+        (proc (fdopen fd "rb"))))
+
+;; Like call-with-output-file but opens the file in 'binary' mode.
+(define (call-with-binary-output-file filename proc)
+  (letfd ((fd (open filename (logior O_WRONLY O_CREAT O_BINARY) #o600)))
+        (proc (fdopen fd "wb"))))
+
+;;
 ;; Libc functions.
 ;;