libc: implement some more terminal functions

Code comes from musl, but is moved to libc.cc to be together with the other functions
already present there.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>