Handle portability better.

Yesterday's attempt was somewhat shortsighted. This one should actually
work.

We avoid the ugliness of having to do the same thing twice somewhat by
putting it in a separate function -- this is still ugly to some extent,
but at least it doesn't copy code around more than just for the function
name.