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
| typedef struct hostent hostent_t; | |
| typedef struct in_addr inaddr_t; | |
| char* dns_nm_to_addr(char* nm){ | |
| hostent_t* hostinfo; | |
| inaddr_t* addr; | |
| hostinfo=gethostbyname(nm); | |
| return inet_ntoa(*(inaddr_t*)(hostinfo->h_addr)); | |
| } |
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| // Types and stuff | |
| #include <ctype.h> | |
| #include <stdint.h> | |
| typedef struct _arr{ |
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <ctype.h> | |
| #ifndef __unix__ | |
| #error Please use unix or replace the unix syscalls with functions/syscalls available on your system. After you have done that, remove this error | |
| #endif | |
| #include <unistd.h> |
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
| unsigned char starts_with(char* _in, char* startsw){ | |
| long unsigned int fma=strlen(_in); | |
| for(unsigned int i=0;i<(fma-1);i++){ | |
| if(_in[i]==0x0||startsw[i]==0x0){ | |
| break; | |
| } | |
| if(_in[i]!=startsw[i]){ | |
| return 1; | |
| } | |
| } |
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
| typedef struct _arr{ | |
| char* arr; | |
| size_t len; | |
| }arr_t; | |
| arr_t lines_from_file(char* filenm){ | |
| arr_t filedata; | |
| filedata.arr=read_file(filenm, &filedata.len); | |
| if(!filedata.arr){ | |
| arr_t a={0, 0}; |
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* getline(FILE* stream){ | |
| size_t bytes=0; | |
| unsigned int capacity=64; | |
| char* buf=malloc(capacity); | |
| char c; | |
| #ifdef __unix__ | |
| while((c=fgetc(stream))!=EOF&&c!='\n') | |
| #else | |
| while((c=fgetc(stream))!=EOF&&c!='\n'&&c!='\r') | |
| #endif // __unix__ |
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* unix_read_file(char* filenm, long unsigned int* len){ | |
| int fd=open(filenm, O_RDONLY); | |
| char* buf=0x0; | |
| if(fd>0){ | |
| struct stat stats; | |
| fstat(fd, &stats); | |
| buf=malloc(stats.st_size+1); | |
| if(buf){ | |
| read(fd, buf, stats.st_size); | |
| buf[stats.st_size]=0x0; |
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(char* InC, char* delim, long unsigned int* len){ | |
| long unsigned int capacity=32; | |
| char** tok=(char**)malloc(capacity*sizeof(char**)); | |
| //printf("%p\n", tok); | |
| tok[0]=strtok(strdup(InC), delim); | |
| { | |
| long unsigned int i=1; | |
| while(tok[i-1]!=NULL){ | |
| if(i+2>=capacity){ |
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
| // Requires <unistd.h> and <stdlib.h> | |
| void ExecuteAsync(char** argv){ | |
| pid_t pid=fork(); | |
| if(pid==0){ | |
| // child process | |
| execv(argv[0], argv); | |
| exit(127); | |
| } |
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <time.h> | |
| #ifndef __unix__ | |
| #error only supports unix! | |
| #endif // __unix__ |