Fix warnings in dbtest.c

Check return values of read() and write().  Avoid some unsigned
comparisons.  Cast a ptrdiff_t value to int for use with %d in a
format string.

[ghudson@mit.edu: rewrap long lines; fix one more warning; commit
message]