in reply to UID 0 and getpwnam

You should be able to test as follows
if( $uid >= 0 ) { ... }
and cover all the valid cases.