/* libanode: the Anode C reference implementation * Copyright (C) 2009-2010 Adam Ierymenko * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /* This contains miscellaneous functions, including some re-implementations * of some functions from string.h. This is to help us port to some platforms * (cough Windows Mobile cough) that lack a lot of the basic C library. */ #ifndef _ANODE_MISC_H #define _ANODE_MISC_H #include #include #include "types.h" #ifndef ANODE_NO_STRING_H #include #include #endif /* Table mapping ASCII characters to themselves or their lower case */ extern const unsigned char Anode_ascii_tolower_table[256]; /* Get the lower case version of an ASCII char */ #define Anode_tolower(c) ((char)Anode_ascii_tolower_table[((unsigned long)((unsigned char)(c)))]) /* Test strings for equality, return nonzero if equal */ static inline unsigned int Anode_streq(const char *restrict a,const char *restrict b) { if ((!a)||(!b)) return 0; while (*a == *(b++)) { if (!*(a++)) return 1; } return 0; } /* Equality test ignoring (ASCII) case */ static inline unsigned int Anode_strcaseeq(const char *restrict a,const char *restrict b) { if ((!a)||(!b)) return 0; while (Anode_tolower(*a) == Anode_tolower(*(b++))) { if (!*(a++)) return 1; } return 0; } /* Safe c-string copy, ensuring that dest[] always ends with zero */ static inline void Anode_str_copy(char *restrict dest,const char *restrict src,unsigned int dest_size) { char *restrict dest_end = dest + (dest_size - 1); while ((*src)&&(dest != dest_end)) *(dest++) = *(src++); *dest = (char)0; } /* Simple memcpy() */ #ifdef ANODE_NO_STRING_H static inline void Anode_memcpy(void *restrict dest,const void *restrict src,unsigned int len) { unsigned int i; for(i=0;i 8 base32 characters and vice versa */ void Anode_base32_5_to_8(const unsigned char *in,char *out); void Anode_base32_8_to_5(const char *in,unsigned char *out); #endif