use ttyname_r if ptsname_r is not available
This commit is contained in:
parent
e86a1feee6
commit
d6f9917389
11
bin/te.c
11
bin/te.c
@ -180,9 +180,9 @@ int x11_setup(struct X11 *x11)
|
||||
x11->buf_x = 0;
|
||||
x11->buf_y = 0;
|
||||
x11->buf = malloc(x11->buf_w * x11->buf_h);
|
||||
if (x11->buf == NULL)
|
||||
if (!x11->buf )
|
||||
{
|
||||
perror("calloc");
|
||||
fprintf(stderr, "Could not allocate terminal buffer\n");
|
||||
return -1;
|
||||
}
|
||||
memset (x11->buf, ' ', x11->buf_w * x11->buf_h);
|
||||
@ -363,7 +363,7 @@ int main()
|
||||
hio = hio_open(HIO_NULL, 0, HIO_NULL, HIO_FEATURE_ALL, 512, HIO_NULL);
|
||||
if (!hio)
|
||||
{
|
||||
printf ("Cannot open hio\n");
|
||||
fprintf (stderr, "Error: Unable to open hio\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -382,6 +382,11 @@ int main()
|
||||
pi.on_read = pty_on_read;
|
||||
pi.on_close = pty_on_close;
|
||||
pty = hio_dev_pty_make(hio, HIO_SIZEOF(*pair), &pi);
|
||||
if (!pty)
|
||||
{
|
||||
fprintf (stderr, "Error: Unable to create pty - %s\n", hio_geterrbmsg(hio));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pair = hio_dev_pty_getxtn(pty);
|
||||
pair->x11 = &x11;
|
||||
|
16
lib/pty.c
16
lib/pty.c
@ -38,6 +38,13 @@
|
||||
#if defined(HAVE_PTY_H)
|
||||
# include <pty.h>
|
||||
#endif
|
||||
#if defined(HAVE_PATHS_H)
|
||||
# include <paths.h>
|
||||
#endif
|
||||
|
||||
#if !defined(_PATH_DEV)
|
||||
# define _PATH_DEV "/dev/"
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
@ -215,7 +222,11 @@ static int dev_pty_make (hio_dev_t* dev, void* ctx)
|
||||
hio_oow_t capa = HIO_COUNTOF(pts_name_buf);
|
||||
|
||||
/* open a pty slave device name */
|
||||
#if defined(HAVE_PTSNAME_R)
|
||||
if (ptsname_r(pfds[0], ptr, capa) != 0)
|
||||
#else
|
||||
if (ttyname_r(pfds[0], ptr, capa) != 0)
|
||||
#endif
|
||||
{
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
@ -233,6 +244,11 @@ static int dev_pty_make (hio_dev_t* dev, void* ctx)
|
||||
goto oops;
|
||||
}
|
||||
|
||||
#if !defined(HAVE_PTSNAME_R)
|
||||
/* ttyname_r() gives something like /dev/ptyp0. change the leading p to t */
|
||||
ptr[HIO_SIZEOF(_PATH_DEV) - 1] = 't';
|
||||
#endif
|
||||
|
||||
/* open a pty slave */
|
||||
pfds[1] = open(ptr, O_RDWR | O_NOCTTY);
|
||||
if (pfds[1] == -1)
|
||||
|
Loading…
Reference in New Issue
Block a user