iio.c: Closedir correctly and return error if we fail to read from the device dir