github.com/gotranspile/cxgo@v0.3.7/libs/sys_stat.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 sysStatH = "sys/stat.h" 10 ) 11 12 func init() { 13 RegisterLibrary(sysStatH, func(c *Env) *Library { 14 intT := types.IntT(4) 15 strT := c.C().String() 16 timevalT := c.GetLibraryType(timeH, "timeval") 17 modeT := types.NamedTGo("mode_t", "csys.Mode", intT) 18 statT := types.NamedTGo("stat", "csys.StatRes", types.StructT([]*types.Field{ 19 {Name: types.NewIdentGo("st_dev", "Dev", intT)}, 20 {Name: types.NewIdentGo("st_ino", "Inode", intT)}, 21 {Name: types.NewIdentGo("st_mode", "Mode", modeT)}, 22 {Name: types.NewIdentGo("st_nlink", "Links", intT)}, 23 {Name: types.NewIdentGo("st_uid", "UID", intT)}, 24 {Name: types.NewIdentGo("st_gid", "GID", intT)}, 25 {Name: types.NewIdentGo("st_rdev", "RDev", intT)}, 26 {Name: types.NewIdentGo("st_size", "Size", types.UintT(8))}, 27 {Name: types.NewIdentGo("st_atime", "ATime", timevalT)}, 28 {Name: types.NewIdentGo("st_mtime", "MTime", timevalT)}, 29 {Name: types.NewIdentGo("st_ctime", "CTime", timevalT)}, 30 {Name: types.NewIdentGo("st_blksize", "BlockSize", intT)}, 31 {Name: types.NewIdentGo("st_blocks", "Blocks", intT)}, 32 })) 33 return &Library{ 34 Imports: map[string]string{ 35 "csys": RuntimePrefix + "csys", 36 }, 37 Types: map[string]types.Type{ 38 "mode_t": modeT, 39 "stat": statT, 40 }, 41 Idents: map[string]*types.Ident{ 42 "stat": c.NewIdent("stat", "csys.Stat", csys.Stat, c.FuncTT(intT, strT, c.PtrT(statT))), 43 "chmod": c.NewIdent("chmod", "csys.Chmod", csys.Chmod, c.FuncTT(intT, strT, modeT)), 44 "mkdir": c.NewIdent("mkdir", "csys.Mkdir", csys.Mkdir, c.FuncTT(intT, strT, modeT)), 45 "S_ISDIR": c.NewIdent("S_ISDIR", "csys.IsDir", csys.IsDir, c.FuncTT(intT, modeT)), 46 }, 47 // TODO 48 Header: ` 49 #include <` + sysTypesH + `> 50 #include <` + sysTimeH + `> 51 52 typedef _cxgo_sint32 mode_t; 53 54 struct stat { 55 _cxgo_sint32 st_dev; /* ID of device containing file */ 56 _cxgo_sint32 st_ino; /* inode number */ 57 mode_t st_mode; /* protection */ 58 _cxgo_sint32 st_nlink; /* number of hard links */ 59 _cxgo_sint32 st_uid; /* user ID of owner */ 60 _cxgo_sint32 st_gid; /* group ID of owner */ 61 _cxgo_sint32 st_rdev; /* device ID (if special file) */ 62 off_t st_size; /* total size, in bytes */ 63 struct timeval st_atime; /* time of last access */ 64 struct timeval st_mtime; /* time of last modification */ 65 struct timeval st_ctime; /* time of last status change */ 66 _cxgo_sint32 st_blksize; /* blocksize for filesystem I/O */ 67 _cxgo_sint32 st_blocks; /* number of blocks allocated */ 68 }; 69 70 _cxgo_sint32 chmod(const char *, mode_t); 71 int fchmod(int, mode_t); 72 int fstat(int, struct stat *); 73 int lstat(const char *restrict, struct stat *restrict); 74 _cxgo_sint32 mkdir(const char *, mode_t); 75 int mkfifo(const char *, mode_t); 76 _cxgo_sint32 stat(const char *restrict, struct stat *restrict); 77 mode_t umask(mode_t); 78 79 _cxgo_sint32 S_ISDIR(mode_t m); 80 81 #define S_IRUSR 1 82 #define S_IWUSR 1 83 #define S_IXUSR 1 84 85 #define S_IRGRP 1 86 #define S_IWGRP 1 87 #define S_IXGRP 1 88 89 #define S_IROTH 1 90 #define S_IWOTH 1 91 #define S_IXOTH 1 92 93 #define S_ISUID 1 94 #define S_ISGID 1 95 #define S_ISVTX 1 96 97 #define S_IFMT 1 98 #define S_IFLNK 1 99 #define S_IFREG 1 100 #define S_IFCHR 1 101 #define S_IFBLK 1 102 #define S_IFIFO 1 103 #define S_IFSOCK 1 104 #define S_IFDIR 1 105 106 int S_ISLNK(int); 107 `, 108 } 109 }) 110 }