util: modernize loop_read() and loop_write() a bit

Let's make use of fd_wait_for_event() here, instead of rolling our own.
util: introduce new dev_urandom() call that is like random_bytes() but doesn't fall back to PRNG
util: simplify mkostemp_safe()

Make it use dev_urandom() and endswith().
util: pass original flags value to mkostemp(), in open_tmpfile()
util: define O_TMPFILE on x86/x86-64, where the generic value is used

On other archs we'll not define it so that open_tmpfile() falls back to
unguessable name + unlink.
util: pick slightly safer open() flags when creating temporary files
always use the same code for creating temporary files

Let's unify our code here, and also always specifiy O_CLOEXEC.