From: Wilfried Göesgens Date: Sun, 30 Nov 2008 23:12:01 +0000 (+0000) Subject: * zero-safe StrtoI/L X-Git-Tag: v7.86~1757 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=5da552611b36dfd7add1c0674f2362275ceee2b7 * zero-safe StrtoI/L * add long hash adaptor --- diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index a8340f493..e9796343f 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -409,6 +409,20 @@ static long FindInHash(HashList *Hash, long HashBinKey) return SearchPos; } + +/** + * \brief another hashing algorithm; treat it as just a pointer to long. + * \param str Our pointer to the long value + * \param len the length of the data pointed to; needs to be sizeof int, else we won't use it! + * \returns the calculated hash value + */ +int Flathash(const char *str, long len) +{ + if (len != sizeof (int)) + return 0; + else return *(int*)str; +} + /** * \brief private abstract wrapper around the hashing algorithm * \param HKey the hash string diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 59316a21f..28358c89a 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -212,6 +212,12 @@ void the_mime_parser(char *partnum, typedef struct StrBuf StrBuf; +typedef struct _ConstStr { + const char *Key; + long len; +}ConstStr; + + StrBuf* NewStrBuf(void); StrBuf* NewStrBufDup(const StrBuf *CopyMe); StrBuf* NewStrBufPlain(const char* ptr, int nChars); @@ -384,6 +390,9 @@ typedef int (*HashFunc)(const char *Str, long Len); typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd); typedef void (*PrintHashDataFunc) (const char *Key, void *Item, int Odd); +int Flathash(const char *str, long len); +#define IKEY(a) (const char*)(&((int)a)), sizeof(int) + HashList *NewHash(int Uniq, HashFunc F); void DeleteHash(HashList **Hash); void HDeleteHash(void *vHash); diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index f5cfbbb37..67a50ece5 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -271,6 +271,8 @@ void HFreeStrBuf (void *VFreeMe) */ long StrTol(const StrBuf *Buf) { + if (Buf == NULL) + return 0; if(Buf->BufUsed > 0) return atol(Buf->buf); else @@ -282,7 +284,9 @@ long StrTol(const StrBuf *Buf) */ int StrToi(const StrBuf *Buf) { - if(Buf->BufUsed > 0) + if (Buf == NULL) + return 0; + if (Buf->BufUsed > 0) return atoi(Buf->buf); else return 0;