github.com/gotranspile/cxgo@v0.3.8-0.20240118201721-29871598a6a2/libs/errno.go (about) 1 package libs 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/gotranspile/cxgo/runtime/libc" 8 "github.com/gotranspile/cxgo/types" 9 ) 10 11 // https://pubs.opengroup.org/onlinepubs/9699919799/ 12 13 func init() { 14 RegisterLibrary("errno.h", func(c *Env) *Library { 15 return &Library{ 16 Header: errnoHeader(), 17 Imports: map[string]string{ 18 "libc": RuntimeLibc, 19 }, 20 Idents: errnoIdents(c), 21 } 22 }) 23 } 24 25 func errnoHeader() string { 26 lines := []string{ 27 "_cxgo_go_int errno = 0;", 28 "char* strerror (_cxgo_go_int errnum);", 29 } 30 31 for _, v := range errnoInfs { 32 lines = append(lines, fmt.Sprintf("const _cxgo_go_int %s = %d;", v.name, v.value)) 33 } 34 res := strings.Join(lines, "\n") 35 return res 36 } 37 38 func errnoIdents(c *Env) map[string]*types.Ident { 39 gint := c.Go().Int() 40 41 res := map[string]*types.Ident{ 42 "errno": c.NewIdent("errno", "libc.Errno", libc.Errno, gint), 43 "strerror": c.NewIdent("strerror", "libc.StrError", libc.StrError, c.FuncTT(c.C().String(), gint)), 44 } 45 46 for _, v := range errnoInfs { 47 res[v.name] = c.NewIdent(v.name, "libc."+v.name, libc.Errno, gint) 48 } 49 50 return res 51 } 52 53 var errnoInfs = []struct { 54 name string 55 value int 56 }{ 57 // Argument list too long. 58 {"E2BIG", 2}, 59 // Permission denied. 60 {"EACCES", 3}, 61 // Address in use. 62 {"EADDRINUSE", 4}, 63 // Address not available. 64 {"EADDRNOTAVAIL", 5}, 65 // Address family not supported. 66 {"EAFNOSUPPORT", 6}, 67 // Resource unavailable, try again (may be the same value as EWOULDBLOCK). 68 {"EAGAIN", 7}, 69 // Connection already in progress. 70 {"EALREADY", 8}, 71 // Bad file descriptor. 72 {"EBADF", 9}, 73 // Bad message. 74 {"EBADMSG", 10}, 75 // Device or resource busy. 76 {"EBUSY", 11}, 77 // Operation canceled. 78 {"ECANCELED", 12}, 79 // No child processes. 80 {"ECHILD", 13}, 81 // Connection aborted. 82 {"ECONNABORTED", 14}, 83 // Connection refused. 84 {"ECONNREFUSED", 15}, 85 // Connection reset. 86 {"ECONNRESET", 16}, 87 // Resource deadlock would occur. 88 {"EDEADLK", 17}, 89 // Destination address required. 90 {"EDESTADDRREQ", 18}, 91 // Mathematics argument out of domain of function. 92 {"EDOM", 19}, 93 // Reserved. 94 {"EDQUOT", 20}, 95 // File exists. 96 {"EEXIST", 21}, 97 // Bad address. 98 {"EFAULT", 22}, 99 // File too large. 100 {"EFBIG", 23}, 101 // Host is unreachable. 102 {"EHOSTUNREACH", 24}, 103 // Identifier removed. 104 {"EIDRM", 25}, 105 // Illegal byte sequence. 106 {"EILSEQ", 26}, 107 // Operation in progress. 108 {"EINPROGRESS", 27}, 109 // Interrupted function. 110 {"EINTR", 28}, 111 // Invalid argument. 112 {"EINVAL", 29}, 113 // I/O error. 114 {"EIO", 30}, 115 // Socket is connected. 116 {"EISCONN", 31}, 117 // Is a directory. 118 {"EISDIR", 32}, 119 // Too many levels of symbolic links. 120 {"ELOOP", 33}, 121 // File descriptor value too large. 122 {"EMFILE", 34}, 123 // Too many links. 124 {"EMLINK", 35}, 125 // Message too large. 126 {"EMSGSIZE", 36}, 127 // Reserved. 128 {"EMULTIHOP", 37}, 129 // Filename too long. 130 {"ENAMETOOLONG", 38}, 131 // Network is down. 132 {"ENETDOWN", 39}, 133 // Connection aborted by network. 134 {"ENETRESET", 40}, 135 // Network unreachable. 136 {"ENETUNREACH", 41}, 137 // Too many files open in system. 138 {"ENFILE", 42}, 139 // No buffer space available. 140 {"ENOBUFS", 43}, 141 // No message is available on the STREAM head read queue. 142 {"ENODATA", 44}, 143 // No such device. 144 {"ENODEV", 45}, 145 // No such file or directory. 146 {"ENOENT", 46}, 147 // Executable file format error. 148 {"ENOEXEC", 47}, 149 // No locks available. 150 {"ENOLCK", 48}, 151 // Reserved. 152 {"ENOLINK", 49}, 153 // Not enough space. 154 {"ENOMEM", 50}, 155 // No message of the desired type. 156 {"ENOMSG", 51}, 157 // Protocol not available. 158 {"ENOPROTOOPT", 52}, 159 // No space left on device. 160 {"ENOSPC", 53}, 161 // No STREAM resources. 162 {"ENOSR", 54}, 163 // Not a STREAM. 164 {"ENOSTR", 55}, 165 // Functionality not supported. 166 {"ENOSYS", 56}, 167 // The socket is not connected. 168 {"ENOTCONN", 57}, 169 // Not a directory or a symbolic link to a directory. 170 {"ENOTDIR", 58}, 171 // Directory not empty. 172 {"ENOTEMPTY", 59}, 173 // Env not recoverable. 174 {"ENOTRECOVERABLE", 60}, 175 // Not a socket. 176 {"ENOTSOCK", 61}, 177 // Not supported (may be the same value as EOPNOTSUPP). 178 {"ENOTSUP", 62}, 179 // Inappropriate I/O control operation. 180 {"ENOTTY", 63}, 181 // No such device or address. 182 {"ENXIO", 64}, 183 // Operation not supported on socket (may be the same value as ENOTSUP). 184 {"EOPNOTSUPP", 65}, 185 // Value too large to be stored in data type. 186 {"EOVERFLOW", 66}, 187 // Previous owner died. 188 {"EOWNERDEAD", 67}, 189 // Operation not permitted. 190 {"EPERM", 68}, 191 // Broken pipe. 192 {"EPIPE", 69}, 193 // Protocol error. 194 {"EPROTO", 79}, 195 // Protocol not supported. 196 {"EPROTONOSUPPORT", 80}, 197 // Protocol wrong type for socket. 198 {"EPROTOTYPE", 81}, 199 // Result too large. 200 {"ERANGE", 82}, 201 // Read-only file system. 202 {"EROFS", 83}, 203 // Invalid seek. 204 {"ESPIPE", 84}, 205 // No such process. 206 {"ESRCH", 85}, 207 // Reserved. 208 {"ESTALE", 86}, 209 // Stream ioctl() timeout. 210 {"ETIME", 87}, 211 // Connection timed out. 212 {"ETIMEDOUT", 88}, 213 // Text file busy. 214 {"ETXTBSY", 89}, 215 // Operation would block (may be the same value as EAGAIN). 216 {"EWOULDBLOCK", 90}, 217 // Cross-device link. }, 218 {"EXDEV", 91}, 219 }