diff --git a/src/fileio.jl b/src/fileio.jl index 42d44c6..67c4879 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -5,10 +5,13 @@ cfopen(filename::String, mode::String) = ccall(:fopen, (Cstring, Cstring), filename, mode) -cfclose(fp::Ptr{Cvoid}) = ccall(:fclose, - Cint, - (Ptr{Cvoid},), - fp) +function cfclose(fp::Ptr{Cvoid}) + (fp == C_NULL) && return + ccall(:fclose, + Cint, + (Ptr{Cvoid},), + fp) +end function cfopen(f::Function, iostream::IOStream, mode::String="r") newfd = Libc.dup(RawFD(fd(iostream))) diff --git a/test/runtests.jl b/test/runtests.jl index ebac209..4d0b6ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -116,6 +116,10 @@ Si 13.00000000 14.00000000 $(frame+1).00000000 0 @test all(seq1 .≈ seq2) end + @testset "missingfile" begin + @test_throws ErrorException("file bla.extxyz cannot be opened for reading") read_frame("bla.extxyz") + end + @testset "AtomsBase" begin seq1 = ExtXYZ.load(infile) ExtXYZ.save(outfile, seq1)