Question

I'm trying to open a geotiff from the ASTER data set, but it gives an error that I've been unable to figure out. Here is my code:

#include "stdlib.h"
#include "stdio.h"
#include "tiffio.h"

void read(void);

void main() {
    read();
    return;
}

void read(void) {
    TIFF* file;

    file = TIFFOpen("./ASTGTM2_N50E002_dem.tif", "r");
    if (file != NULL)
        TIFFClose(file);
    else
        printf( "won't open\n" );
    return;
}

I am compiling like so:

gcc parse.c -ltiff -lm;

This is a part of the output I get:

TIFFOpen: ./ASTGTM2_N50E002_dem.tif: Too many open files.
./ASTGTM2_N50E002_dem.tif: Cannot read TIFF header.

The second message repeats a few hundred times, then

won't open

displays a few hundred times after that.

read() is being called once, why am I getting some 700-odd prints?

I'm running Debian, I checked

lsof | grep ASTGTM2_N50E002_dem.tif

and no one has this file open.

I also followed the suggestion here: https://stackoverflow.com/a/9012019/1877851

I am still receiving the same error. What's going on?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top