[plt-scheme] Is there any way to make a file writable?

From: Ben Goetter (goetter at mazama.net)
Date: Wed Oct 1 10:34:01 EDT 2008

Matthew Flatt wrote:
> There's currently no function in `scheme' to set file permissions. You
> could use the FFI to access chmod():
>   
Or, under Windows, Get/SetFileAttributes:

(define getperms (_bitmask '(
                          error = #xffffffff
                          archive = #x20
                          compressed = #x800
                          device = #x64
                          directory = #x10
                          encrypted = #x4000
                          hidden = #x2
                          normal = #x80
                          not-content-indexed = #x2000
                          offline = #x1000
                          read-only = #x1
                          reparse-point = #x400
                          sparse-file = #x200
                          system = #x4
                          temporary = #x100
                          virtual = #x10000
                          ) _ulong))

(define gfa (get-ffi-obj "GetFileAttributesW"
                         (ffi-lib "KERNEL32")
                         (_fun #:abi 'stdcall _string/utf-16 -> getperms)))

(define setperms (_bitmask '(
                          archive = #x20
                          hidden = #x2
                          normal = #x80
                          not-content-indexed = #x2000
                          offline = #x1000
                          read-only = #x1
                          system = #x4
                          temporary = #x100
                          ) _ulong))

(define sfa (get-ffi-obj "SetFileAttributesW"
                         (ffi-lib "KERNEL32")
                         (_fun #:abi 'stdcall _string/utf-16 setperms -> 
_bool)))

;; call iff gfa returns 'error or sfa returns #f
(define gle (get-ffi-obj "GetLastError"
                         (ffi-lib "KERNEL32")
                         (_fun #:abi 'stdcall -> _ulong)))



Posted on the users mailing list.