Skip to content

Commit 6ac351a

Browse files
authored
Make write(IO, Char) actually return the amount of printed bytes instead of the attempted written bytes. (#56980)
1 parent b80dd58 commit 6ac351a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

base/io.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,10 @@ end
864864

865865
function write(io::IO, c::Char)
866866
u = bswap(reinterpret(UInt32, c))
867-
n = 1
867+
n = 0
868868
while true
869-
write(io, u % UInt8)
869+
n += write(io, u % UInt8)
870870
(u >>= 8) == 0 && return n
871-
n += 1
872871
end
873872
end
874873
# write(io, ::AbstractChar) is not defined: implementations

test/iobuffer.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,9 @@ end
399399
io = IOBuffer(data)
400400
@test read(io) == data
401401
end
402+
403+
@testset "Writing Char to full buffer" begin
404+
io = IOBuffer(;maxsize=1)
405+
write(io, 'a')
406+
@test write(io, 'a') == 0
407+
end

0 commit comments

Comments
 (0)