Skip to content

Commit

Permalink
Merge pull request #108 from alyst/fix_libc_errno
Browse files Browse the repository at this point in the history
gzopen(): use Libc.errno()
  • Loading branch information
sjkelly authored Dec 2, 2023
2 parents e1206d5 + 559c9e8 commit 15407e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Zlib_jll = "83775a58-1f1d-513f-b197-d71354ab007a"

[compat]
julia = "1.9"
Libdl = "1.0"
Zlib_jll = "1.0"
Aqua = "0.8"
Test = "1.0"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Expand Down
4 changes: 2 additions & 2 deletions src/gz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function gzopen(fname::AbstractString, gzmode::AbstractString, gz_buf_size::Inte

gz_file = Zlib_h.gzopen(fname, gzmode)
if gz_file == C_NULL
errno = unsafe_load(cglobal((:errno, :libc), Cint))
errno = Libc.errno()
throw(SystemError("$(fname)", errno))
end
if gz_buf_size != Z_DEFAULT_BUFSIZE
Expand Down Expand Up @@ -236,7 +236,7 @@ function gzdopen(name::AbstractString, fd::Integer, gzmode::AbstractString, gz_b

gz_file = Zlib_h.gzdopen(reinterpret(Cint, dup_fd), gzmode)
if gz_file == C_NULL
errno = unsafe_load(cglobal((:errno, :libc), Cint))
errno = Libc.errno()
throw(SystemError("$(name)", errno))
end
if gz_buf_size != Z_DEFAULT_BUFSIZE
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ try
@test data == data3

# Test gzfdio
@test_throws "No such file or directory" gzopen("wrong_file.gz", "r")
@test_throws "Bad file descriptor" gzdopen("wrong_fd.gz", -1, "r", 1024)

raw_file = open(test_compressed, "r")
gzfile = gzdopen(fd(raw_file), "r")
data4 = read(gzfile, String)
Expand Down

0 comments on commit 15407e2

Please sign in to comment.