HELPLIB.HLB  —  CRTL  decc$write_eof_to_mbx
    Writes an end-of-file message to the mailbox.

    Format

      #include  <unistd.h>

      int decc$write_eof_to_mbx  (int fd);

1  –  Argument

 fd

    File descriptor associated with the mailbox.

2  –  Description

    The decc$write_eof_to_mbx function writes end-of-file message to
    the mailbox.

    For a mailbox that is not a pipe, the write function called with
    an nbytes argument value of 0 sends an end-of-file message to the
    mailbox. For a pipe, however, the only way to write an end-of-
    file message to the mailbox is to close the pipe.

    If the child's standard input is redirected to a pipe through a
    call to the decc$set_child_standard_streams function, the parent
    process can call decc$write_eof_to_mbx for this pipe to send an
    EOF message to the child. It has the same effect as if the child
    read the data from a terminal, and Ctrl/Z was pressed.

    After a call to decc$write_eof_to_mbx, the pipe can be reused
    for communication with another child, for example. This is
    the purpose of decc$write_eof_to_mbx: to allow reuse of the
    pipe instead of having to close it just to send an end-of-file
    message.

3  –  Return Values

    0                  Indicates success.
    -1                 Indicates failure; errno and vaxc$errno are
                       set according to the failure status returned
                       by SYS$QIOW.

4  –  Example

        /*      decc$write_eof_to_mbx_example.c         */

        #include <errno.h>
        #include <stdio.h>
        #include <string.h>

        #include <fcntl.h>
        #include <unistd.h>
        #include <unixio.h>

        #include <descrip.h>
        #include <ssdef.h>
        #include <starlet.h>

        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");
        }

      This example program produces the following result:

        Example ran to completion
Close Help