Convert a mix of latin 1 and UTF-8 to proper UTF-8
A useful idea, and very well implemented.

I'd re-write this condition:


while (!(index &lt; buflen))



as

while (buflen &lt;= index)


Apart from that, I found the code very readable.

It's a good idea to store the received data as int rather than converting to char immediately (though I do worry somewhat about using a signed type in code_point - perhaps its arguments should be narrowed to unsigned char?).

Another minor nit: it's not necessary to assign to buf[3] in the else case, although I see it might aid debugging.

I was never able to get an error return from the program (I tried closing stdout using &gt;&amp; in Bash, and also tried redirecting to /dev/full), but always got an exit status of 0.  That surprised me, as the code looks correct.