[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[S8FFI] Structs

SwikiCodeRobot @> #testS8FFIStructs

"get time of day"
| timeVal timeValPtr lib tv |
timeVal := S8Struct type: #(
	#(tv_sec long)
	#(tv_usec long)
).
timeValPtr := S8Ref refType: timeVal.
lib := S8FFI current library: nil functions:
		#gettimeofday -> (Array with: #int
			with: (Array with: timeValPtr with: #pointer)).
tv := S8Struct @ timeVal value.
lib handle #gettimeofday: tv ref json with: nil json.
self print: 'Seconds since epoch: ', (tv@#tv_sec)


"stores the current process times in the struct tms"
| tms tmsPtr lib struct |
tms := S8Struct type: #(
	#(tms_utime long)
	#(tms_stime long)
	#(tms_cutime long)
	#(tms_cstime long)
).
tmsPtr := S8Ref refType: tms.
lib := S8FFI current library: nil functions:
		#times -> (Array with: #long with: (Array with: tmsPtr)).
struct := S8Struct @ tms value.
lib handle #times: struct ref json.
self print: '	user time: ', (struct@#tms_utime).
self print: '	system time: ', (struct@#tms_stime).
self print: '	user time of children: ', (struct@#tms_cutime).
self print: '	system time of children: ', (struct@#tms_cstime).


References