Skip to content

Commit

Permalink
Make write(IO, Char) actually return the amount of printed bytes inst…
Browse files Browse the repository at this point in the history
…ead of the attempted written bytes. (#56980)
  • Loading branch information
gbaraldi authored Jan 10, 2025
1 parent b80dd58 commit 6ac351a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,10 @@ end

function write(io::IO, c::Char)
u = bswap(reinterpret(UInt32, c))
n = 1
n = 0
while true
write(io, u % UInt8)
n += write(io, u % UInt8)
(u >>= 8) == 0 && return n
n += 1
end
end
# write(io, ::AbstractChar) is not defined: implementations
Expand Down
6 changes: 6 additions & 0 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,9 @@ end
io = IOBuffer(data)
@test read(io) == data
end

@testset "Writing Char to full buffer" begin
io = IOBuffer(;maxsize=1)
write(io, 'a')
@test write(io, 'a') == 0
end

0 comments on commit 6ac351a

Please sign in to comment.