use ttyname_r if ptsname_r is not available
This commit is contained in:
		
							
								
								
									
										11
									
								
								bin/te.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								bin/te.c
									
									
									
									
									
								
							@ -180,9 +180,9 @@ int x11_setup(struct X11 *x11)
 | 
				
			|||||||
	x11->buf_x = 0;
 | 
						x11->buf_x = 0;
 | 
				
			||||||
	x11->buf_y = 0;
 | 
						x11->buf_y = 0;
 | 
				
			||||||
	x11->buf = malloc(x11->buf_w * x11->buf_h);
 | 
						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;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	memset (x11->buf, ' ', x11->buf_w * x11->buf_h);
 | 
						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);
 | 
						hio = hio_open(HIO_NULL, 0, HIO_NULL, HIO_FEATURE_ALL, 512, HIO_NULL);
 | 
				
			||||||
	if (!hio)
 | 
						if (!hio)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		printf ("Cannot open hio\n");
 | 
							fprintf (stderr, "Error: Unable to open hio\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -382,6 +382,11 @@ int main()
 | 
				
			|||||||
		pi.on_read = pty_on_read;
 | 
							pi.on_read = pty_on_read;
 | 
				
			||||||
		pi.on_close = pty_on_close;
 | 
							pi.on_close = pty_on_close;
 | 
				
			||||||
		pty = hio_dev_pty_make(hio, HIO_SIZEOF(*pair), &pi);
 | 
							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 = hio_dev_pty_getxtn(pty);
 | 
				
			||||||
		pair->x11 = &x11;
 | 
							pair->x11 = &x11;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								lib/pty.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								lib/pty.c
									
									
									
									
									
								
							@ -38,6 +38,13 @@
 | 
				
			|||||||
#if defined(HAVE_PTY_H)
 | 
					#if defined(HAVE_PTY_H)
 | 
				
			||||||
#	include <pty.h>
 | 
					#	include <pty.h>
 | 
				
			||||||
#endif
 | 
					#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);
 | 
							hio_oow_t capa = HIO_COUNTOF(pts_name_buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* open a pty slave device name */
 | 
							/* open a pty slave device name */
 | 
				
			||||||
 | 
					#if defined(HAVE_PTSNAME_R)
 | 
				
			||||||
		if (ptsname_r(pfds[0], ptr, capa) != 0)
 | 
							if (ptsname_r(pfds[0], ptr, capa) != 0)
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
							if (ttyname_r(pfds[0], ptr, capa) != 0)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (errno == ERANGE) 
 | 
								if (errno == ERANGE) 
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
@ -233,6 +244,11 @@ static int dev_pty_make (hio_dev_t* dev, void* ctx)
 | 
				
			|||||||
			goto oops;
 | 
								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 */
 | 
							/* open a pty slave */
 | 
				
			||||||
		pfds[1] = open(ptr, O_RDWR | O_NOCTTY);
 | 
							pfds[1] = open(ptr, O_RDWR | O_NOCTTY);
 | 
				
			||||||
		if (pfds[1] == -1)
 | 
							if (pfds[1] == -1)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user