1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 *************************************************************************
11 * Test the SIGPIPE handler in NSPR. This test applies to Unix only.
13 *************************************************************************
16 #if !defined(XP_UNIX) && !defined(XP_OS2)
20 /* This test applies to Unix and OS/2. */
24 #else /* XP_UNIX && OS/2 */
29 #define INCL_DOSQUEUES
30 #define INCL_DOSERRORS
38 static void Test(void *arg)
49 if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) {
51 if (pipe(pipefd) == -1) {
53 fprintf(stderr, "cannot create pipe: %d\n", errno);
58 rv = write(pipefd[1], &c, 1);
60 fprintf(stderr, "write to broken pipe should have failed with EPIPE but returned %d\n", rv);
64 /* Have mercy on the unknown 142 errno, it seems ok */
65 if (errno != EPIPE && errno != 142) {
69 fprintf(stderr, "write to broken pipe failed but with wrong errno: %d\n", errno);
73 printf("write to broken pipe failed with EPIPE, as expected\n");
76 int main(int argc, char **argv)
80 /* This initializes NSPR. */
83 thread = PR_CreateThread(PR_USER_THREAD, Test, NULL, PR_PRIORITY_NORMAL,
84 PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
86 fprintf(stderr, "PR_CreateThread failed\n");
89 if (PR_JoinThread(thread) == PR_FAILURE) {
90 fprintf(stderr, "PR_JoinThread failed\n");