Help opening a terminal

Roe Peterson roe at unibase.UUCP
Thu Jan 5 08:56:01 AEST 1989


>From article <19192 at shemp.CS.UCLA.EDU>, by michael at maui.cs.ucla.edu:
> I cannot get this to work:
> 
> extern int errno;
> main()
> {
> 	int fd;
> 	fd = open ("/dev/tty000", 2);
> 	perror();
** problem here - should be perror("");
> 	printf ("%d %d\n", fd, errno);
> }
> 
> The result of this is error 19, no such device.

I assume you have read/write permission.

I'm not sure why you are getting "no such device" errors on the tty line,
but I know this for sure: if you are opening a tty line, it ALWAYS pays off
to open the thing with O_NDELAY set, to avoid problems with carrier detect
not being there.  Then, make sure the line is on in CLOCAL mode.  Fragment
follows (for system V):

#include <sys/termio.h>
#include <sys/fcntl.h>

	struct termio ttymode;
	int fd;
	fd = open ("/dev/tty000", O_RDWR|O_NDELAY);
	ioctl(fd,TCGETA,&ttymode);
	ttymode.c_cflag |= CLOCAL;
	ioctl(fd,TCSETA,&ttymode);
	close(open("/dev/tty000",O_RDWR));

The close(open()) is required to shut off the O_NDELAY setting.  I know that
the fcntl manual says you can do it with an fcntl call, but the device
driver is not reset by this - use the close(open()).

-- 

                                  Roe Peterson
                                  uunet!attcan!utgpu!tmsoft!mcl!unibase!roe



More information about the Comp.unix.questions mailing list