Skip to content

Commit 9103718

Browse files
gbaraldiKristofferC
authored andcommitted
Make write(IO, Char) actually return the amount of printed bytes instead of the attempted written bytes. (#56980)
(cherry picked from commit 6ac351a)
1 parent 09704c7 commit 9103718

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

base/io.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,10 @@ end
747747

748748
function write(io::IO, c::Char)
749749
u = bswap(reinterpret(UInt32, c))
750-
n = 1
750+
n = 0
751751
while true
752-
write(io, u % UInt8)
752+
n += write(io, u % UInt8)
753753
(u >>= 8) == 0 && return n
754-
n += 1
755754
end
756755
end
757756
# write(io, ::AbstractChar) is not defined: implementations

test/iobuffer.jl

+6
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,9 @@ end
357357
seek(io,0)
358358
@test Base.read_sub(io,v,1,1) == [1,0]
359359
end
360+
361+
@testset "Writing Char to full buffer" begin
362+
io = IOBuffer(;maxsize=1)
363+
write(io, 'a')
364+
@test write(io, 'a') == 0
365+
end

0 commit comments

Comments
 (0)