github.com/gotranspile/cxgo@v0.3.7/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 // TODO 41 Header: ` 42 #include <` + BuiltinH + `> 43 #include <` + StdlibH + `> 44 #include <` + sysTypesH + `> 45 #include <` + sysStatH + `> 46 #include <` + StdioH + `> 47 48 _cxgo_go_uintptr creat(const char *, mode_t); 49 _cxgo_go_uintptr open(const char *, _cxgo_sint32, ...); 50 _cxgo_sint32 fcntl(_cxgo_go_uintptr, _cxgo_sint32, ...); 51 52 _cxgo_sint32 access(const char *, _cxgo_sint32); 53 unsigned alarm(unsigned); 54 _cxgo_sint32 chdir(const char *); 55 _cxgo_sint32 fchdir(int fd); 56 int chown(const char *, uid_t, gid_t); 57 #define close(fd) _cxgo_fileByFD((_cxgo_go_uintptr)fd)->Close() 58 size_t confstr(int, char *, size_t); 59 int dup(int); 60 int dup2(int, int); 61 int execl(const char *, const char *, ...); 62 int execle(const char *, const char *, ...); 63 int execlp(const char *, const char *, ...); 64 int execv(const char *, char *const []); 65 int execve(const char *, char *const [], char *const []); 66 int execvp(const char *, char *const []); 67 #define _exit(v) _Exit(v) 68 int fchown(int, uid_t, gid_t); 69 pid_t fork(void); 70 long fpathconf(int, int); 71 int ftruncate(int, off_t); 72 char *getcwd(char *, _cxgo_go_int); 73 gid_t getegid(void); 74 uid_t geteuid(void); 75 gid_t getgid(void); 76 int getgroups(int, gid_t []); 77 _cxgo_go_int gethostname(char *, _cxgo_go_int); 78 char *getlogin(void); 79 int getlogin_r(char *, size_t); 80 int getopt(int, char * const [], const char *); 81 pid_t getpgrp(void); 82 pid_t getpid(void); 83 pid_t getppid(void); 84 uid_t getuid(void); 85 int isatty(int); 86 int link(const char *, const char *); 87 _cxgo_uint64 lseek(_cxgo_go_uintptr, _cxgo_uint64, _cxgo_sint32); 88 long pathconf(const char *, int); 89 int pause(void); 90 int pipe(int [2]); 91 #define read(fd, p, sz) _cxgo_fileByFD((_cxgo_go_uintptr)fd)->Read(p, sz) 92 #define write(fd, p, sz) _cxgo_fileByFD((_cxgo_go_uintptr)fd)->Write(p, sz) 93 ssize_t readlink(const char *restrict, char *restrict, size_t); 94 _cxgo_sint32 rmdir(const char *); 95 int setegid(gid_t); 96 int seteuid(uid_t); 97 int setgid(gid_t); 98 int setpgid(pid_t, pid_t); 99 pid_t setsid(void); 100 int setuid(uid_t); 101 unsigned sleep(unsigned); 102 int symlink(const char *, const char *); 103 long sysconf(int); 104 pid_t tcgetpgrp(int); 105 int tcsetpgrp(int, pid_t); 106 char *ttyname(int); 107 int ttyname_r(int, char *, size_t); 108 _cxgo_sint32 unlink(const char *); 109 `, 110 } 111 }) 112 }