Back to index

courier  0.68.2
Classes | Defines | Functions
buf.h File Reference
#include <stdlib.h>
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  buf

Defines

#define buf_init(p)   ( (p)->ptr=0, (p)->size=0, (p)->cnt=0)
#define buf_free(p)   do { if ( (p)->ptr) free ((p)->ptr); buf_init(p);} while (0)

Functions

void buf_cpy (struct buf *, const char *)
void buf_cpyn (struct buf *, const char *, size_t)
void buf_cat (struct buf *, const char *)
void buf_catn (struct buf *, const char *, size_t)
void buf_memcpy (struct buf *, const char *, size_t)
void buf_memcat (struct buf *, const char *, size_t)
void buf_trimleft (struct buf *, size_t)
void buf_append (struct buf *, char c)

Class Documentation

struct buf

Definition at line 25 of file buf.h.

Class Members
size_t cnt
char * ptr
size_t size

Define Documentation

#define buf_free (   p)    do { if ( (p)->ptr) free ((p)->ptr); buf_init(p);} while (0)

Definition at line 31 of file buf.h.

#define buf_init (   p)    ( (p)->ptr=0, (p)->size=0, (p)->cnt=0)

Definition at line 30 of file buf.h.


Function Documentation

void buf_append ( struct buf ,
char  c 
)

Definition at line 14 of file buf.c.

{
       char cc[2];

       cc[0]=c;
       cc[1]=0;
       buf_cat(b, cc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void buf_cat ( struct buf ,
const char *   
)

Definition at line 64 of file buf.c.

{
       size_t l=strlen(c);

       if (!buf_allocbuf(b, b->cnt+l+1))
              return;

       strcpy(b->ptr+b->cnt, c);
       b->cnt += l;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void buf_catn ( struct buf ,
const char *  ,
size_t   
)

Definition at line 75 of file buf.c.

{
size_t l;

       for (l=0; l<n; l++)
              if (c[l] == '\0')    break;

       if (!buf_allocbuf(b, b->cnt+l+1))
              return;

       memcpy(b->ptr+b->cnt, c, l);
       b->ptr[b->cnt += l]=0;
}

Here is the call graph for this function:

void buf_cpy ( struct buf ,
const char *   
)

Definition at line 39 of file buf.c.

{
       size_t l=strlen(c);

       if (!buf_allocbuf(b, l+1))
              return;

       strcpy(b->ptr, c);
       b->cnt=l;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void buf_cpyn ( struct buf ,
const char *  ,
size_t   
)

Definition at line 50 of file buf.c.

{
size_t l;

       for (l=0; l<n; l++)
              if (c[l] == '\0')    break;

       if (!buf_allocbuf(b, l+1))
              return;

       memcpy(b->ptr, c, l);
       b->ptr[b->cnt=l]=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void buf_memcat ( struct buf ,
const char *  ,
size_t   
)

Definition at line 98 of file buf.c.

{
       if (!buf_allocbuf(b, b->cnt+n+1))
              return;

       memcpy(b->ptr+b->cnt, c, n);
       b->ptr[b->cnt += n]=0;
}

Here is the call graph for this function:

void buf_memcpy ( struct buf ,
const char *  ,
size_t   
)

Definition at line 89 of file buf.c.

{
       if (!buf_allocbuf(b, n+1))
              return;

       memcpy(b->ptr, c, n);
       b->ptr[b->cnt=n]=0;
}

Here is the call graph for this function:

void buf_trimleft ( struct buf ,
size_t   
)

Definition at line 107 of file buf.c.

{
       if (n >= b->cnt)
              b->cnt=0;
       else
       {
       size_t i;

              for (b->cnt -= n, i=0; i<b->cnt; i++)
                     b->ptr[i]=b->ptr[i+n];
       }
       if (!buf_allocbuf(b, b->cnt+1))
              return;

       b->ptr[b->cnt]=0;
}

Here is the call graph for this function: