* zero-safe StrtoI/L
authorWilfried Göesgens <willi@citadel.org>
Sun, 30 Nov 2008 23:12:01 +0000 (23:12 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 30 Nov 2008 23:12:01 +0000 (23:12 +0000)
* add long hash adaptor

libcitadel/lib/hash.c
libcitadel/lib/libcitadel.h
libcitadel/lib/stringbuf.c

index a8340f493532ba042afcfa698a25e0a763b6c0e2..e9796343f273832ca10926b37ae5f279f9fd6d8e 100644 (file)
@@ -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
index 59316a21f795c636dada3aa4f41d0a1f7a5c899a..28358c89a4cdd80596c69ca62dd988a2c9824d5d 100644 (file)
@@ -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);
index f5cfbbb374866a2d6e45499e0334420db600d4c0..67a50ece57b97c64f1de39dcb550eedc57d5b4ca 100644 (file)
@@ -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;