httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@c2.org
Subject buff.c question
Date Fri, 10 May 1996 23:50:47 GMT
	I wrote the following to read all pending data from a BUFF *
without actually reading from the fd associated with it. I'm not too
BUFF * -clued, so if people could point out glaring errors, it would
be appreciated.
	This is modelled after bflush()

/*
 * Clear the buffered stream such that the incoming buffer
 * is empty
 * Returns # of bytes read
 */
int
bclear(BUFF *fb, char *buf, int len)
{
  if(fb->flags & B_WRERR) return -1;

  if(fb->incnt == 0) return 0;
  if(fb->incnt <= len)
    {
      int i = fb->incnt;
      memcpy(buf, fb->inbase, fb->incnt);
      fb->incnt = 0;
      return i;
    }
  else
    {
      int j, n = fb->incnt;
      unsigned char *x=fb->inbase;

      memcpy(buf, fb->inbase, len);
      for(j = len; j < n; j++) x[j-len] = x[j];

      return len;
    }
}



-- 
Sameer Parekh					Voice:   510-601-9777x3
Community ConneXion, Inc.			FAX:     510-601-9734
The Internet Privacy Provider			Dialin:  510-658-6376
http://www.c2.net/ (or login as "guest")		sameer@c2.net

Mime
View raw message