github.com/gotranspile/cxgo@v0.3.7/libs/sys_time.go (about)

     1  package libs
     2  
     3  import (
     4  	"github.com/gotranspile/cxgo/runtime/csys"
     5  	"github.com/gotranspile/cxgo/types"
     6  )
     7  
     8  const (
     9  	sysTimeH = "sys/time.h"
    10  )
    11  
    12  func init() {
    13  	RegisterLibrary(sysTimeH, func(c *Env) *Library {
    14  		intT := types.IntT(4)
    15  		timeLib := c.LookupLibrary(timeH)
    16  		timevalT := timeLib.GetType("timeval")
    17  		timespecT := timeLib.GetType("timespec")
    18  		_ = timespecT
    19  		return &Library{
    20  			Imports: map[string]string{
    21  				"libc": RuntimeLibc,
    22  				"csys": RuntimePrefix + "csys",
    23  			},
    24  			Idents: map[string]*types.Ident{
    25  				"gettimeofday": c.NewIdent("gettimeofday", "csys.GetTimeOfDay", csys.GetTimeOfDay, c.FuncTT(intT, c.PtrT(timevalT), c.PtrT(nil))),
    26  			},
    27  			// TODO
    28  			Header: `
    29  #include <` + timeH + `>
    30  #include <` + sysTypesH + `>
    31  
    32  typedef struct fd_set {
    33  	long fds_bits[];
    34  } fd_set;
    35  
    36  _cxgo_int32   getitimer(_cxgo_int32, struct itimerval *);
    37  _cxgo_int32   gettimeofday(struct timeval *restrict, void *restrict);
    38  int   select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, struct timeval *restrict);
    39  int   setitimer(int, const struct itimerval *restrict, struct itimerval *restrict);
    40  `,
    41  		}
    42  	})
    43  }