~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to libclamav/jsparse/textbuf.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef TEXTBUF_H
 
2
#define TEXTBUF_H
 
3
struct text_buffer {
 
4
        char *data;
 
5
        size_t pos;
 
6
        size_t capacity;
 
7
};
 
8
 
 
9
static inline int textbuffer_ensure_capacity(struct text_buffer *txtbuf, size_t len)
 
10
{
 
11
        if (txtbuf->pos + len > txtbuf->capacity) {
 
12
                char *d;
 
13
                txtbuf->capacity = MAX(txtbuf->pos + len, txtbuf->capacity + 4096);
 
14
                d = cli_realloc(txtbuf->data, txtbuf->capacity);
 
15
                if(!d)
 
16
                        return -1;
 
17
                txtbuf->data = d;
 
18
        }
 
19
        return 0;
 
20
}
 
21
 
 
22
static inline int textbuffer_append_len(struct text_buffer *txtbuf, const char *s, size_t len)
 
23
{
 
24
        if(textbuffer_ensure_capacity(txtbuf, len) == -1)
 
25
                return -1;
 
26
        memcpy(&txtbuf->data[txtbuf->pos], s, len);
 
27
        txtbuf->pos += len;
 
28
        return 0;
 
29
}
 
30
 
 
31
 
 
32
static inline int textbuffer_append(struct text_buffer *txtbuf, const char *s)
 
33
{
 
34
        size_t len = strlen(s);
 
35
        return textbuffer_append_len(txtbuf, s, len);
 
36
}
 
37
 
 
38
static inline int textbuffer_putc(struct text_buffer *txtbuf, const char c)
 
39
{
 
40
        if(textbuffer_ensure_capacity(txtbuf, 1) == -1)
 
41
                return -1;
 
42
        txtbuf->data[txtbuf->pos++] = c;
 
43
        return 0;
 
44
}
 
45
#endif