From 9c45d9ad13fdf439d44d7443ae75da15ea0223ed Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Mon, 19 Aug 2013 16:39:41 -0400 Subject: Initial checkin Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy. --- sqwebmail/buf.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 sqwebmail/buf.c (limited to 'sqwebmail/buf.c') diff --git a/sqwebmail/buf.c b/sqwebmail/buf.c new file mode 100644 index 0000000..375c1f4 --- /dev/null +++ b/sqwebmail/buf.c @@ -0,0 +1,122 @@ +#include "config.h" +/* +** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for +** distribution information. +*/ + + +/* +*/ +#include +#include "buf.h" +#include "sqwebmail.h" + +void buf_append(struct buf *b, char c) +{ + char cc[2]; + + cc[0]=c; + cc[1]=0; + buf_cat(b, cc); +} + +static int buf_allocbuf(struct buf *b, size_t n) +{ + if (n > b->size) + { + size_t c=n+64; + char *p= b->ptr ? realloc(b->ptr, c):malloc(c); + + if (!p) + return 0; + + b->ptr=p; + b->size=c; + } + return 1; +} + +void buf_cpy(struct buf *b, const char *c) +{ + size_t l=strlen(c); + + if (!buf_allocbuf(b, l+1)) + return; + + strcpy(b->ptr, c); + b->cnt=l; +} + +void buf_cpyn(struct buf *b, const char *c, size_t n) +{ +size_t l; + + for (l=0; lptr, c, l); + b->ptr[b->cnt=l]=0; +} + +void buf_cat(struct buf *b, const char *c) +{ + size_t l=strlen(c); + + if (!buf_allocbuf(b, b->cnt+l+1)) + return; + + strcpy(b->ptr+b->cnt, c); + b->cnt += l; +} + +void buf_catn(struct buf *b, const char *c, size_t n) +{ +size_t l; + + for (l=0; lcnt+l+1)) + return; + + memcpy(b->ptr+b->cnt, c, l); + b->ptr[b->cnt += l]=0; +} + +void buf_memcpy(struct buf *b, const char *c, size_t n) +{ + if (!buf_allocbuf(b, n+1)) + return; + + memcpy(b->ptr, c, n); + b->ptr[b->cnt=n]=0; +} + +void buf_memcat(struct buf *b, const char *c, size_t n) +{ + if (!buf_allocbuf(b, b->cnt+n+1)) + return; + + memcpy(b->ptr+b->cnt, c, n); + b->ptr[b->cnt += n]=0; +} + +void buf_trimleft(struct buf *b, size_t n) +{ + if (n >= b->cnt) + b->cnt=0; + else + { + size_t i; + + for (b->cnt -= n, i=0; icnt; i++) + b->ptr[i]=b->ptr[i+n]; + } + if (!buf_allocbuf(b, b->cnt+1)) + return; + + b->ptr[b->cnt]=0; +} -- cgit v1.2.3