Back to index

courier  0.68.2
rfc1035gettxt.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "rfc1035.h"
00007 #include      <string.h>
00008 
00009 
00010 int rfc1035_rr_gettxt(struct rfc1035_rr *p, int startpos, char buf[256])
00011 {
00012 unsigned l;
00013 
00014        if (startpos < 0 || (unsigned)startpos >= p->rdlength ||
00015               p->rdlength - (unsigned)startpos <=
00016                      (l=(unsigned)(unsigned char)p->rdata[startpos]))
00017        {
00018               buf[0]=0;
00019               return (-1);
00020        }
00021 
00022        ++startpos;
00023 
00024        memcpy(buf, p->rdata + startpos, l);
00025        buf[l]=0;
00026        startpos += l;
00027        if (startpos >= p->rdlength)
00028               startpos= -1;
00029        return (startpos);
00030 }