openpty, posix_openpt: Remove code duplication.