use standard libc funcs for write_statefile()