Additional information: setlocale's side effect on primordial ports happens even if the port's encoding has been individually set using set-port-encoding!. This means that to maintain a specific encoding on these ports (other than the locale's nominal encoding, which is likely to not be binary compatible) it is necessary to set the encoding repeatedly, before any I/O operation after setlocale might have been called. Since the read-only mode of setlocale has this effect, and arbitrary library code might feel entitled to call setlocale for read purposes without documenting that it does so, this really amounts to setting the encoding before every I/O operation.
-zefram