Move to libutil

Move some utility macros and functions to libutil