1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include <stdio.h>
8 :
9 : #include "native_client/src/shared/imc/nacl_imc_c.h"
10 : #include "native_client/src/shared/platform/nacl_error.h"
11 :
12 :
13 : /* Writes the last error message to the standard error. */
14 0 : static void failWithErrno(const char* message) {
15 : char buffer[256];
16 :
17 0 : if (0 == NaClGetLastErrorString(buffer, sizeof(buffer))) {
18 0 : fprintf(stderr, "%s: %s", message, buffer);
19 : }
20 0 : exit(EXIT_FAILURE);
21 : }
22 :
23 1 : int main(int argc, char* argv[]) {
24 : int result;
25 : NaClHandle pair[2];
26 :
27 : UNREFERENCED_PARAMETER(argc);
28 : UNREFERENCED_PARAMETER(argv);
29 :
30 1 : if (0 != NaClSocketPair(pair)) {
31 0 : failWithErrno("SocketPair");
32 : }
33 :
34 1 : if (0 != NaClClose(pair[0])) {
35 0 : failWithErrno("NaClClose");
36 : }
37 :
38 1 : if (0 != NaClClose(pair[1])) {
39 0 : failWithErrno("NaClClose");
40 : }
41 :
42 : /* Checking the double close. It should return -1. */
43 1 : result = NaClClose(pair[0]);
44 1 : if (-1 != result) {
45 0 : fprintf(stderr, "Double NaClClose returned %d, but -1 expected\n", result);
46 0 : exit(EXIT_FAILURE);
47 : }
48 :
49 1 : return 0;
50 1 : }
|