github.com/gotranspile/cxgo@v0.3.7/libs/string.go (about) 1 package libs 2 3 import ( 4 "github.com/gotranspile/cxgo/runtime/libc" 5 "github.com/gotranspile/cxgo/types" 6 ) 7 8 // https://pubs.opengroup.org/onlinepubs/9699919799/ 9 10 func init() { 11 // TODO: should include <locale.h> 12 RegisterLibrary("string.h", func(c *Env) *Library { 13 gintT := c.Go().Int() 14 voidP := c.PtrT(nil) 15 cstrT := c.C().String() 16 return &Library{ 17 Imports: map[string]string{ 18 "libc": RuntimeLibc, 19 }, 20 Idents: map[string]*types.Ident{ 21 "memcmp": c.NewIdent("memcmp", "libc.MemCmp", libc.MemCmp, c.FuncTT(gintT, voidP, voidP, gintT)), 22 "memchr": c.NewIdent("memchr", "libc.MemChr", libc.MemChr, c.FuncTT(cstrT, cstrT, c.Go().Byte(), gintT)), 23 "strlen": c.NewIdent("strlen", "libc.StrLen", libc.StrLen, c.FuncTT(gintT, cstrT)), 24 "strchr": c.NewIdent("strchr", "libc.StrChr", libc.StrChr, c.FuncTT(cstrT, cstrT, c.Go().Byte())), 25 "strrchr": c.NewIdent("strrchr", "libc.StrRChr", libc.StrRChr, c.FuncTT(cstrT, cstrT, c.Go().Byte())), 26 "strstr": c.NewIdent("strstr", "libc.StrStr", libc.StrStr, c.FuncTT(cstrT, cstrT, cstrT)), 27 "strcmp": c.NewIdent("strcmp", "libc.StrCmp", libc.StrCmp, c.FuncTT(gintT, cstrT, cstrT)), 28 "strncmp": c.NewIdent("strncmp", "libc.StrNCmp", libc.StrNCmp, c.FuncTT(gintT, cstrT, cstrT, gintT)), 29 "strcasecmp": c.NewIdent("strcasecmp", "libc.StrCaseCmp", libc.StrCaseCmp, c.FuncTT(gintT, cstrT, cstrT)), 30 "strncasecmp": c.NewIdent("strncasecmp", "libc.StrNCaseCmp", libc.StrNCaseCmp, c.FuncTT(gintT, cstrT, cstrT, gintT)), 31 "strcpy": c.NewIdent("strcpy", "libc.StrCpy", libc.StrCpy, c.FuncTT(cstrT, cstrT, cstrT)), 32 "strncpy": c.NewIdent("strncpy", "libc.StrNCpy", libc.StrNCpy, c.FuncTT(cstrT, cstrT, cstrT, gintT)), 33 "strcat": c.NewIdent("strcat", "libc.StrCat", libc.StrCat, c.FuncTT(cstrT, cstrT, cstrT)), 34 "strncat": c.NewIdent("strncat", "libc.StrNCat", libc.StrNCat, c.FuncTT(cstrT, cstrT, cstrT, gintT)), 35 "strtok": c.NewIdent("strtok", "libc.StrTok", libc.StrTok, c.FuncTT(cstrT, cstrT, cstrT)), 36 "strspn": c.NewIdent("strspn", "libc.StrSpn", libc.StrSpn, c.FuncTT(gintT, cstrT, cstrT)), 37 "strcspn": c.NewIdent("strcspn", "libc.StrCSpn", libc.StrCSpn, c.FuncTT(gintT, cstrT, cstrT)), 38 }, 39 Header: ` 40 #include <` + BuiltinH + `> 41 #include <` + stddefH + `> 42 #include <` + StdlibH + `> 43 44 #define memcpy __builtin_memcpy 45 #define memmove __builtin_memmove 46 #define memset __builtin_memset 47 48 void *memccpy(void *restrict, const void *restrict, int, _cxgo_go_int); 49 void *memchr(const void *, _cxgo_go_byte, _cxgo_go_int); 50 _cxgo_go_int memcmp(const void *, const void *, _cxgo_go_int); 51 char *stpcpy(char *restrict, const char *restrict); 52 char *stpncpy(char *restrict, const char *restrict, size_t); 53 char *strcat(char *restrict, const char *restrict); 54 char *strchr(const char *, _cxgo_go_byte); 55 _cxgo_go_int strcmp(const char *, const char *); 56 _cxgo_go_int strcoll(const char *, const char *); 57 //int strcoll_l(const char *, const char *, locale_t); 58 char *strcpy(char *restrict, const char *restrict); 59 _cxgo_go_int strcspn(const char *, const char *); 60 #define strdup __builtin_strdup 61 #define strndup __builtin_strndup 62 char *strerror(int); 63 //char *strerror_l(int, locale_t); 64 int strerror_r(int, char *, size_t); 65 _cxgo_go_int strlen(const char *); 66 char *strncat(char *restrict, const char *restrict, _cxgo_go_int); 67 _cxgo_go_int strncmp(const char *, const char *, _cxgo_go_int); 68 char *strncpy(char *restrict, const char *restrict, _cxgo_go_int); 69 _cxgo_go_int strnlen(const char *, _cxgo_go_int); 70 char *strpbrk(const char *, const char *); 71 char *strrchr(const char *, _cxgo_go_byte); 72 char *strsignal(int); 73 _cxgo_go_int strspn(const char *, const char *); 74 char *strstr(const char *, const char *); 75 char *strtok(char *restrict, const char *restrict); 76 char *strtok_r(char *restrict, const char *restrict, char **restrict); 77 size_t strxfrm(char *restrict, const char *restrict, size_t); 78 //size_t strxfrm_l(char *restrict, const char *restrict, size_t, locale_t); 79 _cxgo_go_int strcasecmp(const char *s1, const char *s2); 80 _cxgo_go_int strncasecmp(const char *s1, const char *s2, _cxgo_go_int n); 81 `, 82 } 83 }) 84 }