# L-10 MCS 507 Wed 13 Sep 2023 : showhostname.jl # Illustrates the allocation and the conversion # of a C pointer to a Julia string. """ function gethostname() Allocates memory for the hostname first and the converts the pointer to a Julia string. """ function gethostname() hostname = Vector{UInt8}(undef, 128) # ccall((:gethostname, "libc"), Int32, ccall(:gethostname, Int32, (Ptr{UInt8}, Csize_t), hostname, sizeof(hostname)) hostname[end] = 0; # ensure null-termination return unsafe_string(pointer(hostname)) end """ function main() Calls the function gethostname(). """ function main() name = gethostname() println("running on $name") end main()