[gambit-list] Appending 32bit integers to a file

Phil Dawes pdawes at users.sf.net
Thu Mar 29 15:09:39 EDT 2007


Hi Gambit List,

What's the simplest way to append 32bit unsigned integers to a file in 
gambit? (not bothered about maintaining endian portability or anything)

I'm currently using a C hack (see below), but it feels like there ought 
to be something less clunky.

Thanks,

Phil


(c-declare "#include <stdio.h>")

(define fopen
   (c-lambda (nonnull-char-string nonnull-char-string)
       (pointer "FILE")
     "fopen"))

(define fclose
   (c-lambda ((pointer "FILE")) int32 "fclose"))

(define write-u32vector-to-file
   ; args: port, u32-vector, len
   (c-lambda ((pointer "FILE") scheme-object unsigned-int32) int32
        "___result = fwrite((void*)(___BODY_AS(___arg2,___tSUBTYPED)),
                       4, ___arg3, ___arg1);"))

(define read-u32vector-from-file
   ; args: port, u32-vector, len
   (c-lambda ((pointer "FILE") scheme-object unsigned-int32) int32
        "___result = fread((void*)(___BODY_AS(___arg2,___tSUBTYPED)),
                       4, ___arg3, ___arg1);"))




More information about the Gambit-list mailing list