2012-08-06 19:38:35 -06:00
|
|
|
// skip
|
|
|
|
|
2009-10-03 11:37:12 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
/*
|
|
|
|
A trivial example of wrapping a C library in Go.
|
|
|
|
For a more complex example and explanation,
|
|
|
|
see ../gmp/gmp.go.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package stdio
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-07-14 18:17:53 -06:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2009-10-03 11:37:12 -06:00
|
|
|
|
2010-07-14 18:17:53 -06:00
|
|
|
char* greeting = "hello, world";
|
2009-10-03 11:37:12 -06:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
type File C.FILE
|
|
|
|
|
2010-12-17 12:37:11 -07:00
|
|
|
// Test reference to library symbol.
|
|
|
|
// Stdout and stderr are too special to be a reliable test.
|
2012-03-06 21:27:30 -07:00
|
|
|
//var = C.environ
|
2010-12-17 12:37:11 -07:00
|
|
|
|
2009-10-03 11:37:12 -06:00
|
|
|
func (f *File) WriteString(s string) {
|
2009-12-15 16:33:31 -07:00
|
|
|
p := C.CString(s)
|
2010-07-14 18:17:53 -06:00
|
|
|
C.fputs(p, (*C.FILE)(f))
|
2009-12-15 16:33:31 -07:00
|
|
|
C.free(unsafe.Pointer(p))
|
2010-07-14 18:17:53 -06:00
|
|
|
f.Flush()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *File) Flush() {
|
|
|
|
C.fflush((*C.FILE)(f))
|
2009-10-03 11:37:12 -06:00
|
|
|
}
|
2010-07-14 18:17:53 -06:00
|
|
|
|
|
|
|
var Greeting = C.GoString(C.greeting)
|
2011-07-28 10:39:50 -06:00
|
|
|
var Gbytes = C.GoBytes(unsafe.Pointer(C.greeting), C.int(len(Greeting)))
|