Obtaining System Information

The following is an example of obtaining system information, which is not applicable to Windows.

Code:

import std.posix.*

main(): Int64 {
    /* Functions related to system names */
    var os_info = getos()
    println("os info ==> ${os_info}")
    var hostname = gethostname()
    println("hostname ==> ${hostname}")
    var logname: String = getlogin()
    println("logname ==> ${logname}")

    /* Functions related to program running paths */
    var changePath = "/"
    var chdir_result = chdir(changePath)
    println("chdir_result ==> ${chdir_result}")
    var cwd_path: String = getcwd()
    println("cwd_path ==> ${cwd_path}")

    /* Function getpgid related to system IDs */
    var arr: CString = unsafe { LibC.mallocCString(" ") }
    var a: CPointer<UInt8> = arr.getChars()
    var cp: CPointer<UInt32> = CPointer<UInt32>(a)
    var getg = unsafe{ getgroups(0, cp)}
    var s: String = " "
    for (_ in 0..getg) {
        s = s + "\0"
    }
    println(getg)
    var local: UInt32 = 0
    for (temp in 0..getg) {
        unsafe { local = cp.read(Int64(temp)) }
        println("getgroups ==> ${local.toString()}")
    }
    unsafe { LibC.free(arr)}
    return 0
}

Results (vary depending on the system):

Linux version 4.15.0-159-generic (buildd@lgw01-amd64-055) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021
hostname ==> e124e6e0fe0f
logname ==> root
chdir_result ==> 0
cwd_path ==> /
1
getgroups ==> 1309868064