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