home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / sigpipe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.0 KB  |  75 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  *************************************************************************
  21.  *
  22.  * Test: sigpipe.c
  23.  *
  24.  *     Test the SIGPIPE handler in NSPR.  This test applies to Unix only.
  25.  *
  26.  *************************************************************************
  27.  */
  28.  
  29. #if !defined(XP_UNIX)
  30.  
  31. int main()
  32. {
  33.     /* This test applies to Unix only. */
  34.     return 0;
  35. }
  36.  
  37. #else /* XP_UNIX */
  38.  
  39. #include "nspr.h"
  40.  
  41. #include <stdio.h>
  42. #include <unistd.h>
  43. #include <errno.h>
  44.  
  45. int main()
  46. {
  47.     int pipefd[2];
  48.     int rv;
  49.     char c = '\0';
  50.  
  51.     /* This initializes NSPR. */
  52.     PR_SetError(0, 0);
  53.  
  54.     if (pipe(pipefd) == -1) {
  55.         fprintf(stderr, "cannot create pipe: %d\n", errno);
  56.         exit(1);
  57.     }
  58.     close(pipefd[0]);
  59.  
  60.     rv = write(pipefd[1], &c, 1);
  61.     if (rv != -1) {
  62.         fprintf(stderr, "write to broken pipe should have failed with EPIPE but returned %d\n", rv);
  63.         exit(1);
  64.     }
  65.     if (errno != EPIPE) {
  66.         fprintf(stderr, "write to broken pipe failed but with wrong errno: %d\n", errno);
  67.         exit(1);
  68.     }
  69.     printf("write to broken pipe failed with EPIPE, as expected\n");
  70.     printf("PASSED\n");
  71.     return 0;
  72. }
  73.  
  74. #endif /* XP_UNIX */
  75.