Uname but using a system call

Linux specific forum
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Uname but using a system call

Post by luis »

I was looking in the forum for a way of getting some info about the Linux version / type for some logging and I found many examples launching the binary uname using RunProgram(), but it seems it can also be done with a system call.

Code: Select all

Structure new_utsname 
  sysname.a[64+1] 
  nodename.a[64+1] 
  release.a[64+1] 
  version.a[64+1] 
  machine.a[64+1]
  domainname.a[64+1]
EndStructure

Define buf.new_utsname

Debug uname_(@buf) ; 0 = success

ShowMemoryViewer(@buf,SizeOf(new_utsname))

Debug PeekS(@buf\sysname,-1,#PB_Ascii) ; Linux
Debug PeekS(@buf\nodename,-1,#PB_Ascii) ; LINUX-MINT
Debug PeekS(@buf\release,-1,#PB_Ascii) ; 5.15.0-60-generic
Debug PeekS(@buf\version,-1,#PB_Ascii) ; #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023
Debug PeekS(@buf\machine,-1,#PB_Ascii) ; x86_64
Debug PeekS(@buf\domainname,-1,#PB_Ascii) ; (none)
"Have you tried turning it off and on again ?"
A little PureBasic review