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

     1  package libs
     2  
     3  import (
     4  	"github.com/gotranspile/cxgo/runtime/cnet"
     5  	"github.com/gotranspile/cxgo/types"
     6  )
     7  
     8  const (
     9  	netdbH = "netdb.h"
    10  )
    11  
    12  func init() {
    13  	RegisterLibrary(netdbH, func(c *Env) *Library {
    14  		strT := c.C().String()
    15  		intT := types.IntT(4)
    16  		hostentT := types.NamedTGo("hostent", "cnet.HostEnt", types.StructT([]*types.Field{
    17  			{Name: types.NewIdentGo("h_name", "Name", strT)},
    18  			{Name: types.NewIdentGo("h_aliases", "Aliases", c.PtrT(strT))},
    19  			{Name: types.NewIdentGo("h_addrtype", "AddrType", intT)},
    20  			{Name: types.NewIdentGo("h_length", "Length", intT)},
    21  			{Name: types.NewIdentGo("h_addr_list", "AddrList", c.PtrT(strT))},
    22  		}))
    23  		return &Library{
    24  			Imports: map[string]string{
    25  				"cnet": RuntimePrefix + "cnet",
    26  			},
    27  			Types: map[string]types.Type{
    28  				"hostent": hostentT,
    29  			},
    30  			Idents: map[string]*types.Ident{
    31  				"gethostbyname": c.NewIdent("gethostbyname", "cnet.GetHostByName", cnet.GetHostByName, c.FuncTT(c.PtrT(hostentT), strT)),
    32  			},
    33  		}
    34  	})
    35  }