Add more diagnostic info here
Add more diagnostic output and make sure the value being tested is i, not val
Handle value -> NULL gracefully like NetBSD does

Sponsored-by: EMC Isilon
FreeBSD doesn't understand the f mode flag like NetBSD does
Add some diagnostic output