Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ end
function filesize(s::IOStream)
sz = @_lock_ios s ccall(:ios_filesize, Int64, (Ptr{Cvoid},), s.ios)
if sz == -1
err = Libc.errno()
throw(IOError(string("filesize: ", Libc.strerror(err), " for ", s.name), err))
# if `s` is not seekable `ios_filesize` can fail, so fall back to slower stat method
sz = filesize(stat(s))
end
return sz
end
Expand Down
5 changes: 4 additions & 1 deletion stdlib/Mmap/src/Mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Anonymous() = Anonymous("",false,true)
Base.isopen(::Anonymous) = true
Base.isreadable(::Anonymous) = true
Base.iswritable(a::Anonymous) = !a.readonly
Base.isfile(::Anonymous) = true

# const used for zeroed, anonymous memory
gethandle(io::Anonymous) = INVALID_OS_HANDLE
Expand Down Expand Up @@ -86,6 +87,8 @@ grow!(::Anonymous,o::Integer,l::Integer) = return
function grow!(io::IO, offset::Integer, len::Integer)
pos = position(io)
filelen = filesize(io)
# If non-regular file skip trying to grow since we know that will fail the ftruncate syscall
filelen == 0 && !isfile(io) && return
if filelen < offset + len
failure = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd(io), offset+len)
Base.systemerror(:ftruncate, failure != 0)
Expand Down Expand Up @@ -218,7 +221,7 @@ function mmap(io::IO,
# platform-specific mmapping
@static if Sys.isunix()
prot, flags, iswrite = settings(file_desc, shared)
if requestedSizeLarger
if isfile(io) && requestedSizeLarger # add a condition to this line to ensure it only checks files
if iswrite
if grow
grow!(io, offset, len)
Expand Down