Use ssize_t for the return type of read/write instead of int.

Ported from upstream commit by crigler.
play nicely with -std=c99
Fix error handling for read from stdin in attach.c

attach.c did not correctly handle a read from stdin when read returned
an error. The code assigned the return value of read to pkt.len (an
unsigned char) before checking the value. This prevented the error check
from working correctly, since an unsigned integer can never be < 0.

A packet with an invalid length was then sent to the master, which then
sent 255 bytes of garbage to the program.

Fix the bug in attach.c and the unchecked packet length bug in master.c.

Report and initial patch by Enrico Scholz.
Add AIX support to openpty and forkpty.

Patch by Ross Mohn.