How to get your UID with PLT Scheme under UNIX

Via Eli on comp.lang.scheme:

#lang scheme
;; using the /proc filesystem
(call-with-input-file "/proc/self/loginuid" read)
;; running `id'
(require scheme/system)
(let ([o (open-output-string)])
  (parameterize ([current-output-port o]) (system "id -u"))
  (read (open-input-string (get-output-string o))))
;; calling getuid()
(require scheme/foreign)
(unsafe!)
((get-ffi-obj 'getuid #f (_fun -> _int)))

Leave a Reply

Your email address will not be published. Required fields are marked *