Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ************************************************************************* |
michael@0 | 8 | * |
michael@0 | 9 | * Test: sigpipe.c |
michael@0 | 10 | * |
michael@0 | 11 | * Test the SIGPIPE handler in NSPR. This test applies to Unix only. |
michael@0 | 12 | * |
michael@0 | 13 | ************************************************************************* |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #if !defined(XP_UNIX) && !defined(XP_OS2) |
michael@0 | 17 | |
michael@0 | 18 | int main(void) |
michael@0 | 19 | { |
michael@0 | 20 | /* This test applies to Unix and OS/2. */ |
michael@0 | 21 | return 0; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | #else /* XP_UNIX && OS/2 */ |
michael@0 | 25 | |
michael@0 | 26 | #include "nspr.h" |
michael@0 | 27 | |
michael@0 | 28 | #ifdef XP_OS2 |
michael@0 | 29 | #define INCL_DOSQUEUES |
michael@0 | 30 | #define INCL_DOSERRORS |
michael@0 | 31 | #include <os2.h> |
michael@0 | 32 | #endif |
michael@0 | 33 | |
michael@0 | 34 | #include <stdio.h> |
michael@0 | 35 | #include <unistd.h> |
michael@0 | 36 | #include <errno.h> |
michael@0 | 37 | |
michael@0 | 38 | static void Test(void *arg) |
michael@0 | 39 | { |
michael@0 | 40 | #ifdef XP_OS2 |
michael@0 | 41 | HFILE pipefd[2]; |
michael@0 | 42 | #else |
michael@0 | 43 | int pipefd[2]; |
michael@0 | 44 | #endif |
michael@0 | 45 | int rv; |
michael@0 | 46 | char c = '\0'; |
michael@0 | 47 | |
michael@0 | 48 | #ifdef XP_OS2 |
michael@0 | 49 | if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) { |
michael@0 | 50 | #else |
michael@0 | 51 | if (pipe(pipefd) == -1) { |
michael@0 | 52 | #endif |
michael@0 | 53 | fprintf(stderr, "cannot create pipe: %d\n", errno); |
michael@0 | 54 | exit(1); |
michael@0 | 55 | } |
michael@0 | 56 | close(pipefd[0]); |
michael@0 | 57 | |
michael@0 | 58 | rv = write(pipefd[1], &c, 1); |
michael@0 | 59 | if (rv != -1) { |
michael@0 | 60 | fprintf(stderr, "write to broken pipe should have failed with EPIPE but returned %d\n", rv); |
michael@0 | 61 | exit(1); |
michael@0 | 62 | } |
michael@0 | 63 | #ifdef SYMBIAN |
michael@0 | 64 | /* Have mercy on the unknown 142 errno, it seems ok */ |
michael@0 | 65 | if (errno != EPIPE && errno != 142) { |
michael@0 | 66 | #else |
michael@0 | 67 | if (errno != EPIPE) { |
michael@0 | 68 | #endif |
michael@0 | 69 | fprintf(stderr, "write to broken pipe failed but with wrong errno: %d\n", errno); |
michael@0 | 70 | exit(1); |
michael@0 | 71 | } |
michael@0 | 72 | close(pipefd[1]); |
michael@0 | 73 | printf("write to broken pipe failed with EPIPE, as expected\n"); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | int main(int argc, char **argv) |
michael@0 | 77 | { |
michael@0 | 78 | PRThread *thread; |
michael@0 | 79 | |
michael@0 | 80 | /* This initializes NSPR. */ |
michael@0 | 81 | PR_SetError(0, 0); |
michael@0 | 82 | |
michael@0 | 83 | thread = PR_CreateThread(PR_USER_THREAD, Test, NULL, PR_PRIORITY_NORMAL, |
michael@0 | 84 | PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); |
michael@0 | 85 | if (thread == NULL) { |
michael@0 | 86 | fprintf(stderr, "PR_CreateThread failed\n"); |
michael@0 | 87 | exit(1); |
michael@0 | 88 | } |
michael@0 | 89 | if (PR_JoinThread(thread) == PR_FAILURE) { |
michael@0 | 90 | fprintf(stderr, "PR_JoinThread failed\n"); |
michael@0 | 91 | exit(1); |
michael@0 | 92 | } |
michael@0 | 93 | Test(NULL); |
michael@0 | 94 | |
michael@0 | 95 | printf("PASSED\n"); |
michael@0 | 96 | return 0; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | #endif /* XP_UNIX */ |