Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Jan 1996 08:15:16 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        current@freebsd.org, dyson@freebsd.org
Subject:   new pipes fail several tests #2
Message-ID:  <199601302115.IAA26417@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
Writes to a pipe with no reader don't return -1/EPIPE.

Bruce

#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>

#define check(what, expected)	assert((what, expected))

sig_atomic_t caught;

static void catch(int s)
{
    caught = 1;
}

int main(void)
{
  char buf[1];
  int fd[2];
  int r;

  r = pipe(fd);
  check("pipe", r == 0);
  check("signal", signal(SIGPIPE, catch) != SIG_ERR);
  r = close(fd[0]);
  check("close", r == 0);
  r = write(fd[1], buf, 1);
  printf("wrote %d bytes, errno = %d, caught = %d\n", r, errno, caught);
  check("write", r == -1);
  check("write", errno == EPIPE);
  check("write", caught == 1);
  return 0;
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601302115.IAA26417>