We should be checking for integer overflow, rather than checking if size is 0.
Additionally, we should set errno to ENOMEM when this overflow happens.
Finally, the most efficient implementation of the round-up-to-2 algorithm involves the clz intrinsic.
Previously we needed to include headers required by the various
sudo*h files. Now those files are more self-sufficient and we
should only include headers needed by code in the various .c files.