RUNNER_ASSERT_ERRNO_MSG(fstat(fd1, &fs1) == 0, "fstat failed");
RUNNER_ASSERT_ERRNO_MSG(fstat(fd2, &fs2) == 0, "fstat failed");
- if (fs1.st_size != fs2.st_size) //if files are identical size will be the same
+ if (fs1.st_size < fs2.st_size) {
return -1;
+ }
+
+ if (fs1.st_size > fs2.st_size) {
+ return 1;
+ }
+
+ //since Linux 2.6.12, mmap returns EINVAL if length is 0
+ //if both lengths are 0, files are actually the same
+ if (0 == fs1.st_size && 0 == fs2.st_size) {
+ return 0;
+ }
//mapping files to process memory
RUNNER_ASSERT_ERRNO_MSG((h1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd1, 0 )) != MAP_FAILED,