C code I've found myself writing repeatedly