Add code for computing CRC over a buf

This commit is contained in:
Andreas Öman 2010-06-22 08:00:56 +00:00
parent a120185c8a
commit e0cc0d7f5b
2 changed files with 22 additions and 0 deletions

View file

@ -23,6 +23,7 @@
#include <string.h>
#include <stdarg.h>
#include "htsbuf.h"
#include "tvhead.h"
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@ -118,6 +119,7 @@ htsbuf_append(htsbuf_queue_t *hq, const void *buf, size_t len)
memcpy(hd->hd_data, buf, len);
}
/**
*
*/
@ -275,3 +277,21 @@ htsbuf_appendq(htsbuf_queue_t *hq, htsbuf_queue_t *src)
TAILQ_INSERT_TAIL(&hq->hq_q, hd, hd_link);
}
}
/**
*
*/
uint32_t
htsbuf_crc32(htsbuf_queue_t *hq, uint32_t crc)
{
htsbuf_data_t *hd;
TAILQ_FOREACH(hd, &hq->hq_q, hd_link)
crc = crc32(hd->hd_data + hd->hd_data_off,
hd->hd_data_len - hd->hd_data_off,
crc);
return crc;
}

View file

@ -66,4 +66,6 @@ size_t htsbuf_drop(htsbuf_queue_t *hq, size_t len);
size_t htsbuf_find(htsbuf_queue_t *hq, uint8_t v);
uint32_t htsbuf_crc32(htsbuf_queue_t *q, uint32_t crc);
#endif /* HTSBUF_H__ */