[TUHS] EOF on pipes?

Rudi Blom rudi.j.blom at gmail.com
Tue Feb 27 02:03:55 AEST 2018


>From a piece of code I have in some SCO UNIX 3.2V4.2 source. SCO
doesn't have pipes, but you can simulate them.

	int fd[2]
	int rc;
	struct strfdinsert ins;
	queue_t *pointer = (queue_t *)NULL;

	rc = -1;
	/*
	 * First open the stream clone device "/dev/spx" twice,
	 * obtaining the two file descriptors.
	 */
	if ( (fd[0] = open(SPX_DEVICE, O_RDWR)) < 0)
	{
		gen_trace(gtr_flag, "-gen_pipe(): -open(fd[0]): %s\n", strerror(errno));
		break;
	}
	if ( (fd[1] = open(SPX_DEVICE, O_RDWR)) < 0)
	{
		gen_trace(gtr_flag, ">gen_pipe(): -open(fd[1]): %s\n", strerror(errno));
		close(fd[0]);
		break;
	}

	/*
	 * Now link these two streams together with an
	 * I_FDINSERT ioctl.
	 */
	ins.ctlbuf.buf     = (char *) &pointer; /* no ctl info, just the ptr */
	ins.ctlbuf.maxlen  = sizeof(queue_t *);
	ins.ctlbuf.len     = sizeof(queue_t *);
	ins.databuf.buf    = (char *) 0;        /* no data to send */
	ins.databuf.len    = -1; /* magic: must be -1, not 0, for stream pipe */
	ins.databuf.maxlen = 0;
	ins.fildes = fd[1];     /* the fd to connect with fd[0] */
	ins.flags  = 0;         /* nonpriority message */
	ins.offset = 0;         /* offset of pointer in control buffer */
	if (ioctl(fd[0], I_FDINSERT, (char * ) &ins) < 0)
	{
		gen_trace(gtr_flag, ">gen_pipe(): -ioctl(I_FDINSERT): %s\n", strerror(errno));
		close(fd[0]);
		close(fd[1]);
		break;
	}


More information about the TUHS mailing list