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
|
|
|
|
|
|
|
|
var Stdout = (*File)(C.stdout)
|
|
|
|
var Stderr = (*File)(C.stderr)
|
|
|
|
|
|
|
|
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)
|