]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testcshared/testdata/libgo2/libgo2.go
5f6cfd00397af1356712f59d2c7ae8c0f07213d0
[gostls13.git] / misc / cgo / testcshared / testdata / libgo2 / libgo2.go
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
6
7 package main
8
9 // Test a shared library created by -buildmode=c-shared that does not
10 // export anything.
11
12 import (
13         "fmt"
14         "os"
15         "syscall"
16 )
17
18 // To test this we want to communicate between the main program and
19 // the shared library without using any exported symbols.  The init
20 // function creates a pipe and Dups the read end to a known number
21 // that the C code can also use.
22
23 const (
24         fd = 30
25 )
26
27 func init() {
28         var p [2]int
29         if e := syscall.Pipe(p[0:]); e != nil {
30                 fmt.Fprintf(os.Stderr, "pipe: %v\n", e)
31                 os.Exit(2)
32         }
33
34         if e := dup2(p[0], fd); e != nil {
35                 fmt.Fprintf(os.Stderr, "dup2: %v\n", e)
36                 os.Exit(2)
37         }
38
39         const str = "PASS"
40         if n, e := syscall.Write(p[1], []byte(str)); e != nil || n != len(str) {
41                 fmt.Fprintf(os.Stderr, "write: %d %v\n", n, e)
42                 os.Exit(2)
43         }
44
45         if e := syscall.Close(p[1]); e != nil {
46                 fmt.Fprintf(os.Stderr, "close: %v\n", e)
47                 os.Exit(2)
48         }
49 }
50
51 func main() {
52 }