Import of mg from OpenBSD 5.4.