Implement <pty.h>.

Based on the package/apps/Terminal implementation. I'll switch them over
shortly. This also lets us build the toybox version of netcat.

Change-Id: Ia922a100141a67409264b43b937eeca07b21f344
Fix mbstate_t strict-aliasing violations.

(cherry picked from commit bde8bd5fcc15d48e03b4f9a391c44b5f2363ce13)
libc: Fix strict aliasing violation.

(cherry picked from commit 62b01955410b766ca27e31d9cec8334903987230)