The problem with your code was staring us right in the face!
You see that function you wrote called read()
? Yeah, that's not good. It collides with the standard library's function by the same name (despite different parameters). So it ends up getting called by libtiff--instead of getting data out of the file, it opens recursively, forever until the program can't open files anymore, so libtiff stops trying to read.
Rename your function and all will be well.