<commit_before>;; -*- Mode: Irken -*-

(cinclude "sys/utsname.h")

(define (uname)
  (%backend (c llvm)
    (let ((utsname (%callocate (struct utsname) 1)))
      (%%cexp ((buffer (struct utsname)) -> int) "uname (%0)" utsname)
      {sysname=  (copy-cstring (%%cexp ((buffer (struct utsname)) -> cstring) "%0->sysname" utsname))
       nodename= (copy-cstring (%%cexp ((buffer (struct utsname)) -> cstring) "%0->nodename" utsname))
       release=  (copy-cstring (%%cexp ((buffer (struct utsname)) -> cstring) "%0->release" utsname))
       version=  (copy-cstring (%%cexp ((buffer (struct utsname)) -> cstring) "%0->version" utsname))
       machine=  (copy-cstring (%%cexp ((buffer (struct utsname)) -> cstring) "%0->machine" utsname))
       }))
  (%backend bytecode
    (let ((utsname (%%cexp (-> (list string)) "plat")))
      (match utsname with
        (sysname nodename release version machine)
        -> {sysname=sysname
            nodename=nodename
            release=release
            version=version
            machine=machine}
        _ 
        -> (raise (:UnameFailed utsname))
        )))
  )
      

       <commit_msg>converted to new FFI.<commit_after>;; -*- Mode: Irken -*-

;; This should really go into lib/os.scm or somewhere like that.
;; *or* we put posix-only stuff here.

(require-ffi 'posix)

(define (uname)

  ;; probably useful outside this fun.
  (define (get-string s*)
    (let ((s0* (%c-aref char s* 0))
          (slen (posix/strlen s0*)))
      (%c-sfromc #f s0* slen)))

  (let ((utsname* (malloc (struct utsname)))
        (_ (syscall (posix/uname utsname*)))
        (result
         {sysname  = (get-string (%c-sref utsname.sysname utsname*))
          nodename = (get-string (%c-sref utsname.nodename utsname*))
          release  = (get-string (%c-sref utsname.release utsname*))
          version  = (get-string (%c-sref utsname.version utsname*))
          machine  = (get-string (%c-sref utsname.machine utsname*))}))
    (free utsname*)
    result
    ))
{'fraction_non_alphanumeric': 0.17131474103585656, 'fraction_numerical': 0.005478087649402391, 'mean_word_length': 2.652727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2521919', 'n_tokens_mistral': 702, 'n_tokens_neox': 692, 'n_words': 177}