The convention (back from Unix) is that errno is only set on failure. Simpler fix would just to silently ignore NULL case.