libc: reduce code duplication.