github.com/gotranspile/cxgo@v0.3.8-0.20240118201721-29871598a6a2/libs/unistd.go (about)

     1  package libs
     2  
     3  import (
     4  	"github.com/gotranspile/cxgo/runtime/cnet"
     5  	"github.com/gotranspile/cxgo/runtime/stdio"
     6  	"github.com/gotranspile/cxgo/types"
     7  )
     8  
     9  const (
    10  	unistdH = "unistd.h"
    11  )
    12  
    13  func init() {
    14  	RegisterLibrary(unistdH, func(c *Env) *Library {
    15  		modeT := c.GetLibraryType(sysStatH, "mode_t")
    16  		uintptrT := c.Go().Uintptr()
    17  		fdT := uintptrT
    18  		intT := types.IntT(4)
    19  		gintT := c.Go().Int()
    20  		ulongT := types.UintT(8)
    21  		strT := c.C().String()
    22  		return &Library{
    23  			Imports: map[string]string{
    24  				"stdio": RuntimePrefix + "stdio",
    25  				"csys":  RuntimePrefix + "csys",
    26  				"cnet":  RuntimePrefix + "cnet",
    27  			},
    28  			Idents: map[string]*types.Ident{
    29  				"creat":       c.NewIdent("creat", "stdio.Create", stdio.Create, c.FuncTT(fdT, strT, modeT)),
    30  				"open":        c.NewIdent("open", "stdio.Open", stdio.Open, c.VarFuncTT(fdT, strT, intT)),
    31  				"fcntl":       c.NewIdent("fcntl", "stdio.FDControl", stdio.FDControl, c.VarFuncTT(intT, fdT, intT)),
    32  				"chdir":       c.NewIdent("chdir", "stdio.Chdir", stdio.Chdir, c.FuncTT(intT, strT)),
    33  				"rmdir":       c.NewIdent("rmdir", "stdio.Rmdir", stdio.Rmdir, c.FuncTT(intT, strT)),
    34  				"unlink":      c.NewIdent("unlink", "stdio.Unlink", stdio.Unlink, c.FuncTT(intT, strT)),
    35  				"access":      c.NewIdent("access", "stdio.Access", stdio.Access, c.FuncTT(intT, strT, intT)),
    36  				"lseek":       c.NewIdent("lseek", "stdio.Lseek", stdio.Lseek, c.FuncTT(ulongT, fdT, ulongT, intT)),
    37  				"getcwd":      c.NewIdent("getcwd", "stdio.GetCwd", stdio.GetCwd, c.FuncTT(strT, strT, gintT)),
    38  				"gethostname": c.NewIdent("gethostname", "cnet.GetHostname", cnet.GetHostname, c.FuncTT(gintT, strT, gintT)),
    39  			},
    40  		}
    41  	})
    42  }