/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ /* decc$write_eof_to_mbx_example.c */ #include #include #include #include #include #include #include #include #include int decc$write_eof_to_mbx( int ); main() { int status, nbytes, failed = 0; int fd, fd2[2]; short int channel; $DESCRIPTOR(mbxname_dsc, "TEST_MBX"); char c; /* first try a mailbox created by SYS$CREMBX */ status = sys$crembx(0, &channel, 0, 0, 0, 0, &mbxname_dsc, 0, 0); if ( status != SS$_NORMAL ) { printf("sys$crembx failed: %s\n",strerror(EVMSERR, status)); failed = 1; } if ( (fd = open(mbxname_dsc.dsc$a_pointer, O_RDWR, 0)) == -1 ) { perror("? open mailbox"); failed = 1; } if ( decc$write_eof_to_mbx(fd) == -1 ) { perror("? decc$write_eof_to_mbx to mailbox"); failed = 1; } if ( (nbytes = read(fd, &c, 1)) != 0 || errno != 0 ) { perror("? read mailbox"); printf("? nbytes = %d\n", nbytes); failed = 1; } if ( close(fd) == -1 ) { perror("? close mailbox"); failed = 1; } /* Now do the same thing with a pipe */ errno = 0; /* Clear errno for consistency */ if ( pipe(fd2) == -1 ) { perror("? opening pipe"); failed = 1; } if ( decc$write_eof_to_mbx(fd2[1]) == -1 ) { perror("? decc$write_eof_to_mbx to pipe"); failed = 1; } if ( (nbytes = read(fd2[0], &c, 1)) != 0 || errno != 0 ) { perror("? read pipe"); printf("? nbytes = %d\n", nbytes); failed = 1; } /* Close both file descriptors involved with the pipe */ if ( close(fd2[0]) == -1 ) { perror("close(fd2[0])"); failed = 1; } if ( close(fd2[1]) == -1 ) { perror("close(fd2[1])"); failed = 1; } if ( failed ) puts("?Example program failed"); else puts("Example ran to completion"); }