This file contains 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
long longpow(const long val, long pw){ | |
long res=val; | |
while(--pw)res*=val; | |
return res; | |
} |
This file contains 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
_Bool starts_with(const char* restrict str, const char* restrict sw){ | |
while(*sw) | |
if(*sw++!=*str++)return 0; | |
return 1; | |
} |
This file contains 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 <stddef.h> | |
#include <memory.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
This file contains 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
void reverse_bytes(char* restrict bytes, const size_t len){ | |
for(size_t i=0;i<len/2;i++){ | |
char tmp=bytes[i]; | |
bytes[i]=bytes[len-1-i]; | |
bytes[len-1-i]=tmp; | |
} | |
} | |
// str must have 11 bytes allocated to it | |
void int_to_str(int val, char* str){ |
This file contains 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
void str_clear(char* restrict str){ | |
while(*str)*str++=0; | |
} | |
void str_set(char* restrict str, const char set){ | |
while(*str)*str++=set; | |
} |
This file contains 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
// file_count will add one to the count because zero is reserved for errors | |
size_t file_count(const char* dir_nm){ | |
DIR* dir=opendir(dir_nm); | |
if(!dir)return 0; | |
struct dirent* entity=readdir(dir); | |
size_t count=0; | |
for(;readdir(dir);count++); | |
closedir(dir); | |
return count; | |
} |
This file contains 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
_Bool strcmp_until(const char* s1,const char* s2,const char until){ | |
for(size_t i=0;s1[i]!=until;i++) | |
if(s1[i]!=s2[i])return 1; | |
return 0; | |
} |
This file contains 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
_Bool starts_with_word(const char* str, const char* word){ | |
for(size_t i=0;;i++){ | |
if(!((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')||str[i]=='_')){ | |
if(word[i])return 1; | |
break; | |
} | |
if(str[i]!=word[i]){ | |
return 1; | |
} |
This file contains 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
_Bool starts_with(const char* in, const char* sw){ | |
for(size_t i=0;sw[i];i++) | |
if(in[i]!=sw[i]) | |
return 1; | |
return 0; | |
} |
This file contains 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
// returns position of the last byte in an array or string whose length is known. | |
size_t get_last_byte_ex(const char* const bytes, const char byte,size_t len, _Bool* const exists){ | |
while(bytes[len]!=byte){ | |
if(!len){ | |
*exists=0; | |
return 0; | |
} | |
len--; | |
} | |
NewerOlder