Skip to content

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)))

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*