bump the max key size to 512 bytes. fixes #1714
 This is a combination of 2 commits.

enforce the max key size with a runtime check
fix whitespace
add test for long database key
include sys/stat.h to fix warning on gcc 4.7
make conditional statement more readable