Skip to content

Commit

Permalink
closes #261
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Sep 13, 2023
1 parent 5b92df3 commit e8ffc37
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/misc_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ function filecmp(path1::AbstractString, path2::AbstractString)
if !(isfile(stat1) && isfile(stat2)) || filesize(stat1) != filesize(stat2)
return false
end

compare_buffers(b1, b2, n) = begin
if VERSION > v"1.10.0-"
Base.memcmp(
Base.unsafe_convert(Ptr{UInt8}, b1),
Base.unsafe_convert(Ptr{UInt8}, b2),
n
)
else
Base._memcmp(b1, b2, n)
end
end

stat1 == stat2 && return true # same file
open(path1, "r") do file1
open(path2, "r") do file2
Expand All @@ -183,7 +196,7 @@ function filecmp(path1::AbstractString, path2::AbstractString)
n1 = readbytes!(file1, buf1)
n2 = readbytes!(file2, buf2)
n1 != n2 && return false
0 != Base._memcmp(buf1, buf2, n1) && return false
0 != compare_buffers(buf1, buf2, n1) && return false
end
return eof(file1) == eof(file2)
end
Expand Down

0 comments on commit e8ffc37

Please sign in to comment.