Fix portability problems on Darwin.

Resolves bugs revealed by 511555584e609029b8bfa97baea433111f59de3b.