]> git.ipfire.org Git - thirdparty/util-linux.git/commit
write: correctly handle wide characters
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Wed, 15 Mar 2023 15:16:31 +0000 (16:16 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Mar 2023 10:48:41 +0000 (11:48 +0100)
commit8a7b8456d1dc0e7ca557d1ac31f638986704757f
tree4497a8c668052b8741a0fbb19513f5c9da12191e
parent4a2d7c4725ad895fc1cd3f473e193352118fd4b0
write: correctly handle wide characters

Do this by replacing fputc_careful() (notice that the description said
it's locale-aware ‒ it very much is /not/), with a fputs_careful() which
does the same thing, but if it were to output a byte in the \123 format,
first it checks whether this byte starts a valid multibyte character.

If it does, and that character is printable, write it verbatim.
This means that
  echo 'foo åäö ąęćźżń bar' | write nabijaczleweli pts/4
instead of
  foo \303\245\303\244\303\266
  \304\205\304\231\304\207\305\272\305\274\305\204 bar
yields
  foo åäö ąęćźżń bar
or, more realistically, from a message I got earlier today,
  Filip powiedzia\305\202 \305\274e zap\305\202aci jutro
becomes
  Filip powiedział że zapłaci jutro

Invalid/non-printable sequences get processed as before.

Line reading in write must become getline() to avoid dealing with
partial characters: for example on input consisting solely of
ąęćźżń, where every {1} is an instance, the output would be
  {42}ąęć\305\272żń{84}ąęćź\305\274ń{84}ąęćźż\305\204{39}
with just fixed-512 fgets()

Bug-Debian: https://bugs.debian.org/826596
include/carefulputc.h
login-utils/last.c
term-utils/write.c