How OpenSSH does portable. 

1) Assume a sane target OS (OpenBSD) - Code to that standard.

2) Build and maintain code on the above, using modern C

3) Provide portability shims to correctly do things that other OS's don't provide, only for those that need it. 
No #ifdef maze.
No compromise on what the intrinsic functions actually do. 
Standard intrinsics.
Don't re-implement libc.