helpers.c
/**
 * pts_open
 *
 * open a pts device and returns the name of the slave tty device.
 *
 * arguments
 * slave_name       the name of the slave device
 * slave_name_size  the size of the buffer passed via slave_name
 *
 * return values
 * on failure either -2 or -1 (errno set) is returned.
 * on success, the file descriptor of the master device is returned.
 */
pts_open
open a pts device and returns the name of the slave tty device.

arguments
slave_name       the name of the slave device
slave_name_size  the size of the buffer passed via slave_name

return values
on failure either -2 or -1 (errno set) is returned.
on success, the file descriptor of the master device is returned.
pts_open open a pts device and returns the name of the slave tty device . arguments slave_name the name of the slave device slave_name_size the size of the buffer passed via slave_name return values on failure either - 2 or - 1 ( errno set ) is returned . on success the file descriptor of the master device is returned .
int pts_open(char *slave_name, size_t slave_name_size) {
    int fdm;
    char *sn_tmp;
    fdm = open("/dev/ptmx", O_RDWR);
    if (fdm == -1) return -1;
    sn_tmp = ptsname(fdm);
    if (!sn_tmp) {
        close(fdm);
        return -2;
    }
    strncpy(slave_name, sn_tmp, slave_name_size);
    slave_name[slave_name_size - 1] = '\0';
    if (grantpt(fdm) == -1) {
        close(fdm);
        return -1;
    }
    if (unlockpt(fdm) == -1) {
        close(fdm);
        return -1;
    }
    return fdm;
}
int pts_open ( char * slave_name , size_t slave_name_size ) { int fdm ; char * sn_tmp ; fdm = open ( " " , O_RDWR ) ; if ( fdm == -1 ) return -1 ; sn_tmp = ptsname ( fdm ) ; if ( ! sn_tmp ) { close ( fdm ) ; return -2 ; } strncpy ( slave_name , sn_tmp , slave_name_size ) ; slave_name [ slave_name_size - 1 ] = ' \0 ' ; if ( grantpt ( fdm ) == -1 ) { close ( fdm ) ; return -1 ; } if ( unlockpt ( fdm ) == -1 ) { close ( fdm ) ; return -1 ; } return fdm ; }
pts_open
 open a pts device and returns the name of the slave tty device.
pts_open open a pts device and returns the name of the slave tty device .
// Open master ptmx device // Get the slave name // Grant, then unlock