func Fread(ptr *[]byte, size1, size2 int32, f *File) int32 {
	newBuffer := make([]byte, size1*size2)
	n, err := f.OsFile.Read(newBuffer)
	for i, b := range newBuffer {
		(*ptr)[i] = b
	}
	if err != nil {
		return -1
	}
	return int32(n)
}
Fread handles fread().

Reads an array of count elements, each one with a size of size bytes, from
the stream and stores them in the block of memory specified by ptr.

The position indicator of the stream is advanced by the total amount of bytes
read.

The total amount of bytes read if successful is (size*count).
package noarch
import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"reflect"
	"strings"
)
var (
	Stdin  = NewFile(os.Stdin)
	Stdout = NewFile(os.Stdout)
	Stderr = NewFile(os.Stderr)
)
type File struct {
	OsFile *os.File
}
func Fopen(filePath, mode []byte) *File {
	var file *os.File
	var err error
	sFilePath := CStringToString(filePath)
	switch CStringToString(mode) {
	case "r":
		file, err = os.OpenFile(sFilePath, os.O_RDONLY, 0655)
	case "r+":
		file, err = os.OpenFile(sFilePath, os.O_RDWR, 0655)
	case "a":
		file, err = os.OpenFile(sFilePath, os.O_WRONLY|os.O_APPEND, 0655)
	case "a+":
		file, err = os.OpenFile(sFilePath, os.O_RDWR|os.O_APPEND, 0655)
	case "w":
		file, err = os.OpenFile(sFilePath, os.O_RDWR|os.O_CREATE, 0655)
	case "w+":
		file, err = os.OpenFile(sFilePath, os.O_RDWR|os.O_CREATE, 0655)
	default:
		panic(fmt.Sprintf("unsupported file mode: %s", mode))
	}
	if err != nil {
		return nil
	}
	return NewFile(file)
}
func Fclose(f *File) int32 {
	err := f.OsFile.Close()
	if err != nil {
		return 1
	}
	return 0
}
func Remove(filePath []byte) int32 {
	if os.Remove(CStringToString(filePath)) != nil {
		return -1
	}
	return 0
}
func Rename(oldName, newName []byte) int32 {
	from := CStringToString(oldName)
	to := CStringToString(newName)
	if os.Rename(from, to) != nil {
		return -1
	}
	return 0
}
func Fputs(str []byte, stream *File) int32 {
	if stream == nil {
		return -1
	}
	s := CStringToString(str)
	n, err := stream.OsFile.WriteString(s)
	if err != nil {
		panic(err)
	}
	return int32(n)
}
func Tmpfile() *File {
	f, err := ioutil.TempFile("", "")
	if err != nil {
		return nil
	}
	return NewFile(f)
}
func Fgets(str []byte, num32 int32, stream *File) []byte {
	num := int(num32)
	buf := make([]byte, num)
	n, err := stream.OsFile.Read(buf)
	if err != nil {
		return []byte{}
	}
	if n == num {
		return buf[:n-1]
	}
	return buf[:n]
}
func Gets(str []byte) []byte {
	_, err := Stdin.OsFile.Read(str)
	if err != nil {
		return []byte{}
	}
	return str
}
func Rewind(stream *File) {
	stream.OsFile.Seek(0, 0)
}
func Feof(stream *File) int32 {
	buf := make([]byte, 1)
	_, err := stream.OsFile.Read(buf)
	result := 0
	if err == io.EOF {
		result = 1
	}
	stream.OsFile.Seek(-1, 1)
	return int32(result)
}
func NewFile(f *os.File) *File {
	return &File{
		OsFile: f,
	}
}
func Tmpnam(str []byte) []byte {
	f, err := ioutil.TempFile("", "")
	if err != nil {
		return []byte{}
	}
	f.Close()
	return []byte(f.Name())
}
func Fflush(stream *File) int32 {
	err := stream.OsFile.Sync()
	if err != nil {
		return 1
	}
	return 0
}
func Fprintf(f *File, format []byte, args ...interface{}) int32 {
	realArgs := []interface{}{}
	typeOfByteSlice := reflect.TypeOf([]byte(nil))
	for _, arg := range args {
		if reflect.TypeOf(arg) == typeOfByteSlice {
			realArgs = append(realArgs, CStringToString(arg.([]byte)))
		} else {
			realArgs = append(realArgs, arg)
		}
	}
	n, err := fmt.Fprintf(f.OsFile, CStringToString(format), realArgs...)
	if err != nil {
		return -1
	}
	return int32(n)
}
func Fscanf(f *File, format []byte, args ...interface{}) int32 {
	realArgs := prepareArgsForScanf(args)
	goFormat := CStringToString(format)
	iter := 0
again:
	n, err := fmt.Fscanf(f.OsFile, goFormat, realArgs...)
	if err != nil {
		if strings.Contains(err.Error(), "unexpected newline") && iter < 100 {
			iter++
			goto again
		}
		return -1
	}
	finalizeArgsForScanf(realArgs, args)
	return int32(n)
}
func finalizeArgsForScanf(realArgs []interface{}, args []interface{}) {
	typeOfStringRef := reflect.TypeOf(new(string))
	for i, arg := range realArgs {
		if reflect.TypeOf(arg) == typeOfStringRef {
			s := *arg.(*string)
			copy(args[i].([]byte), []byte(s+"\x00"))
		} else {
			GoPointerToCPointer(arg, args[i])
		}
	}
}
func prepareArgsForScanf(args []interface{}) []interface{} {
	realArgs := []interface{}{}
	typeOfByteSlice := reflect.TypeOf([]byte(nil))
	for _, arg := range args {
		if reflect.TypeOf(arg) == typeOfByteSlice {
			realArgs = append(realArgs, new(string))
		} else {
			realArgs = append(realArgs, CPointerToGoPointer(arg))
		}
	}
	return realArgs
}
func getc(f *os.File) int32 {
	buffer := make([]byte, 1)
	_, err := f.Read(buffer)
	if err != nil {
		return -1
	}
	return int32(buffer[0])
}
func Fgetc(stream *File) int32 {
	return int32(getc(stream.OsFile))
}
func Fputc(c int32, f *File) int32 {
	if f == nil {
		return -1
	}
	n, err := f.OsFile.Write([]byte{byte(c)})
	if err != nil {
		return 0
	}
	return int32(n)
}
func Getchar() int32 {
	return int32(getc(Stdin.OsFile))
}
func Fseek(f *File, offset int32, origin int32) int32 {
	n, err := f.OsFile.Seek(int64(offset), int(origin))
	if err != nil {
		return -1
	}
	return int32(n)
}
func Ftell(f *File) int32 {
	return int32(Fseek(f, 0, 1))
}