Skip to content

Commit 170b5bf

Browse files
committed
print error when file is empty
1 parent 52e1ff9 commit 170b5bf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/dispatchers/file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,10 +1238,16 @@ ncmpi_inq_file_format(const char *filename,
12381238
DEBUG_RETURN_ERROR(NC_EFILE)
12391239
}
12401240
}
1241-
/* get first 8 bytes of file */
1241+
/* get first 8 bytes of file, which contains the file signature */
1242+
errno = 0;
12421243
rlen = read(fd, signature, 8);
12431244
if (rlen != 8) {
12441245
close(fd); /* ignore error */
1246+
if (rlen == 0 && errno == 0) {
1247+
fprintf(stderr, "Error: empty file %s\n", filename);
1248+
else
1249+
fprintf(stderr, "Error: fail to read signature of file %s\n",
1250+
filename);
12451251
DEBUG_RETURN_ERROR(NC_EFILE)
12461252
}
12471253
if (close(fd) == -1) {

0 commit comments

Comments
 (0)