int ret2;
ret = mmap_full_file(conf.inputs[i], O_RDONLY, &audio_file_data,
&audio_file_size, &fd);
- if (ret < 0)
+ if (ret < 0) {
+ PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf.inputs[i]);
goto out;
+ }
ret = compute_afhi(conf.inputs[i], audio_file_data, audio_file_size,
fd, &afhi);
if (ret < 0)
PARA_ERROR(FGETS, "fgets error"), \
PARA_ERROR(EOF, "end of file"), \
PARA_ERROR(READ_PATTERN, "did not read expected pattern"), \
+ PARA_ERROR(EMPTY, "file is empty"), \
#define ALSA_WRITE_ERRORS \
goto out;
}
*size = file_status.st_size;
+ /*
+ * If the file is empty, *size is zero and mmap() would return EINVAL
+ * (Invalid argument). This error is common enough to spend an extra
+ * error code which explicitly states the problem.
+ */
+ ret = -E_EMPTY;
+ if (*size == 0)
+ goto out;
+ /*
+ * If fd refers to a directory, mmap() returns ENODEV (No such device),
+ * at least on Linux. "Is a directory" seems to be more to the point.
+ */
+ ret = -ERRNO_TO_PARA_ERROR(EISDIR);
+ if (S_ISDIR(file_status.st_mode))
+ goto out;
+
ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map);
out:
if (ret < 0 || !fd_ptr)