*** buff.c	Wed Jun 14 11:30:11 2000
--- buff.new	Wed Jun 14 11:28:41 2000
***************
*** 1323,1325 ****
--- 1323,1411 ----
      ap_bpush_iol(fb, iol);
      return fb;
  }
+ 
+ 
+ /* modified version of bread() that doesn't remove the string from the buff */
+ API_EXPORT(int) ap_blookstring(BUFF *fb, void *buf, ap_size_t nbyte,
+                                ap_ssize_t *bytes_read)
+ {
+     int nrd;
+     ap_ssize_t i;
+     ap_status_t rv;
+     int wn;
+     
+     /* Various errors -- unchanged from original */
+     if (fb->flags & B_RDERR) {
+         *bytes_read = 0;
+ 	return fb->saved_errno;
+     }
+     if (nbyte == 0) {
+         *bytes_read = 0;
+ 	return APR_SUCCESS;
+     }
+ 
+     if (!(fb->flags & B_RD)) {
+ 	/* Unbuffered reading.  First check if there was something in the
+ 	 * buffer from before we went unbuffered. */
+ 	if (fb->incnt) {
+ 	    i = (fb->incnt > nbyte) ? nbyte : fb->incnt;
+ 	    memcpy(buf, fb->inptr, i);
+             /* remove the part of the code that advances the pointer */
+             *bytes_read = i;
+ 	    return APR_SUCCESS;
+ 	}
+         /* not sure about this... */
+ 	return read_with_errors(fb, buf, nbyte, bytes_read);
+     }
+ 
+     nrd = fb->incnt;
+ 
+     /* if we can fill the buffer, just do it and return
+        in this case we just skip advancing the pointer */
+ 
+     /* we can't read more than the buffersize 'cause we need to
+        preserve it. If it is bigger, we return up to buffsize */
+     
+     if (nrd >= nbyte) {
+ 	memcpy(buf, fb->inptr, nbyte);
+         *bytes_read = nbyte;
+ 	return APR_SUCCESS;
+     }
+ 
+     /* read contents of buffer and return immediately*/
+     if (nrd > 0) {
+ 	memcpy(buf, fb->inptr, nrd);
+         return APR_SUCCESS;
+     }
+ 
+     /* if EOF return */
+     if (fb->flags & B_EOF) {
+         *bytes_read = nrd;
+ 	return APR_SUCCESS;
+     }
+ 
+     /* not EOF so continue reading up to EOF or buffer size */
+     
+     /* do a single read */
+     /* if there isn't room for whats left of the char* provided, read
+        what you can into the buffer. Otherwise, read a bufferworth */
+     if (nbyte >= (fb->bufsiz - fb->incnt)) {
+         wn = fb->bufsiz - fb->incnt;
+     } else {
+         wn = nbyte;
+     }
+     
+     /* read into hold buffer, then memcpy */
+     rv = read_with_errors(fb, fb->inptr, wn, &i);
+     if (rv != APR_SUCCESS) {
+         *bytes_read = nrd;
+         return rv;
+     }
+     
+     fb->incnt = fb->incnt + i;
+     memcpy(buf, fb->inptr, i);
+     
+     *bytes_read = nrd + i;
+     return APR_SUCCESS;
+ 
+ }
