Last active
July 13, 2021 06:31
-
-
Save alsamitech/bd1c1859bdaf6b03459a6f0e23b6a76a to your computer and use it in GitHub Desktop.
atokl that isn't security and error checking hell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char** atokl(const char* const InC, const char* const delim, long unsigned int* len){ | |
| // eight as that provides room for small splitting operations | |
| long unsigned int capacity=8; | |
| char** tok=(char**)malloc(capacity*sizeof(char**)); | |
| if(!tok)return 0x0; | |
| tok[0]=strtok(strdup(InC), delim); | |
| { | |
| long unsigned int i=1; | |
| while(tok[i-1]!=NULL){ | |
| if(i+2>=capacity){ | |
| capacity*=2; | |
| tok=(char**)realloc(tok, capacity*sizeof(char**)); | |
| if(!tok){ | |
| // something failed | |
| free(tok[0]); | |
| free(tok); | |
| return 0x0; | |
| } | |
| } | |
| tok[i++]=strtok(NULL, delim); | |
| } | |
| *len=i; | |
| /*EBRACE*/} | |
| return tok; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment