github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/misc/swig/stdio/file.swig (about) 1 /* Copyright 2011 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 /* A trivial example of wrapping a C library using SWIG. */ 6 7 %{ 8 #include <stdio.h> 9 #include <stdlib.h> 10 %} 11 12 %typemap(gotype) const char * "string" 13 %typemap(in) const char * %{ 14 $1 = malloc($input.n + 1); 15 memcpy($1, $input.p, $input.n); 16 $1[$input.n] = '\0'; 17 %} 18 %typemap(freearg) const char * %{ 19 free($1); 20 %} 21 22 FILE *fopen(const char *name, const char *mode); 23 int fclose(FILE *); 24 int fgetc(FILE *);