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