buffer.c (107487) | buffer.c (109660) |
---|---|
1/* Code for the buffer data structure. */ 2 | 1/* Code for the buffer data structure. */ 2 |
3/* $FreeBSD: head/contrib/cvs/src/buffer.c 107487 2002-12-02 03:17:49Z peter $ */ | 3/* $FreeBSD: head/contrib/cvs/src/buffer.c 109660 2003-01-21 22:01:38Z peter $ */ |
4 5#include <assert.h> 6#include "cvs.h" 7#include "buffer.h" 8 9#if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) 10 11#ifdef HAVE_WINSOCK_H --- 91 unchanged lines hidden (view full) --- 103 struct buffer_data *alc; 104 char *space; 105 int i; 106 107 /* Allocate buffer_data structures in blocks of 16. */ 108#define ALLOC_COUNT (16) 109 110 alc = ((struct buffer_data *) | 4 5#include <assert.h> 6#include "cvs.h" 7#include "buffer.h" 8 9#if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT) 10 11#ifdef HAVE_WINSOCK_H --- 91 unchanged lines hidden (view full) --- 103 struct buffer_data *alc; 104 char *space; 105 int i; 106 107 /* Allocate buffer_data structures in blocks of 16. */ 108#define ALLOC_COUNT (16) 109 110 alc = ((struct buffer_data *) |
111 malloc (ALLOC_COUNT * sizeof (struct buffer_data))); | 111 xmalloc (ALLOC_COUNT * sizeof (struct buffer_data))); |
112 space = (char *) valloc (ALLOC_COUNT * BUFFER_DATA_SIZE); 113 if (alc == NULL || space == NULL) 114 return; 115 for (i = 0; i < ALLOC_COUNT; i++, alc++, space += BUFFER_DATA_SIZE) 116 { 117 alc->next = free_buffer_data; 118 free_buffer_data = alc; 119 alc->text = space; --- 31 unchanged lines hidden (view full) --- 151 if (data->size > 0) 152 return 0; 153 return 1; 154} 155 156#ifdef SERVER_FLOWCONTROL 157/* 158 * Count how much data is stored in the buffer.. | 112 space = (char *) valloc (ALLOC_COUNT * BUFFER_DATA_SIZE); 113 if (alc == NULL || space == NULL) 114 return; 115 for (i = 0; i < ALLOC_COUNT; i++, alc++, space += BUFFER_DATA_SIZE) 116 { 117 alc->next = free_buffer_data; 118 free_buffer_data = alc; 119 alc->text = space; --- 31 unchanged lines hidden (view full) --- 151 if (data->size > 0) 152 return 0; 153 return 1; 154} 155 156#ifdef SERVER_FLOWCONTROL 157/* 158 * Count how much data is stored in the buffer.. |
159 * Note that each buffer is a malloc'ed chunk BUFFER_DATA_SIZE. | 159 * Note that each buffer is a xmalloc'ed chunk BUFFER_DATA_SIZE. |
160 */ 161 162int 163buf_count_mem (buf) 164 struct buffer *buf; 165{ 166 struct buffer_data *data; 167 int mem = 0; --- 623 unchanged lines hidden (view full) --- 791 792 /* If we found a newline, copy the line into a memory buffer, 793 and remove it from BUF. */ 794 if (data != NULL) 795 { 796 char *p; 797 struct buffer_data *nldata; 798 | 160 */ 161 162int 163buf_count_mem (buf) 164 struct buffer *buf; 165{ 166 struct buffer_data *data; 167 int mem = 0; --- 623 unchanged lines hidden (view full) --- 791 792 /* If we found a newline, copy the line into a memory buffer, 793 and remove it from BUF. */ 794 if (data != NULL) 795 { 796 char *p; 797 struct buffer_data *nldata; 798 |
799 p = malloc (len + 1); | 799 p = xmalloc (len + 1); |
800 if (p == NULL) 801 return -2; 802 *line = p; 803 804 nldata = data; 805 data = buf->data; 806 while (data != nldata) 807 { --- 422 unchanged lines hidden (view full) --- 1230 1231struct buffer * 1232stdio_buffer_initialize (fp, child_pid, input, memory) 1233 FILE *fp; 1234 int child_pid; 1235 int input; 1236 void (*memory) PROTO((struct buffer *)); 1237{ | 800 if (p == NULL) 801 return -2; 802 *line = p; 803 804 nldata = data; 805 data = buf->data; 806 while (data != nldata) 807 { --- 422 unchanged lines hidden (view full) --- 1230 1231struct buffer * 1232stdio_buffer_initialize (fp, child_pid, input, memory) 1233 FILE *fp; 1234 int child_pid; 1235 int input; 1236 void (*memory) PROTO((struct buffer *)); 1237{ |
1238 struct stdio_buffer_closure *bc = malloc (sizeof (*bc)); | 1238 struct stdio_buffer_closure *bc = xmalloc (sizeof (*bc)); |
1239 1240 bc->fp = fp; 1241 bc->child_pid = child_pid; 1242 1243 return buf_initialize (input ? stdio_buffer_input : NULL, 1244 input ? NULL : stdio_buffer_output, 1245 input ? NULL : stdio_buffer_flush, 1246 (int (*) PROTO((void *, int))) NULL, --- 427 unchanged lines hidden (view full) --- 1674 1675 if (count + 2 > pb->holdbufsize) 1676 { 1677 char *n; 1678 1679 /* We didn't allocate enough space in the initialize 1680 function. */ 1681 | 1239 1240 bc->fp = fp; 1241 bc->child_pid = child_pid; 1242 1243 return buf_initialize (input ? stdio_buffer_input : NULL, 1244 input ? NULL : stdio_buffer_output, 1245 input ? NULL : stdio_buffer_flush, 1246 (int (*) PROTO((void *, int))) NULL, --- 427 unchanged lines hidden (view full) --- 1674 1675 if (count + 2 > pb->holdbufsize) 1676 { 1677 char *n; 1678 1679 /* We didn't allocate enough space in the initialize 1680 function. */ 1681 |
1682 n = realloc (pb->holdbuf, count + 2); | 1682 n = xrealloc (pb->holdbuf, count + 2); |
1683 if (n == NULL) 1684 { 1685 (*pb->buf->memory_error) (pb->buf); 1686 return ENOMEM; 1687 } 1688 pb->holdbuf = n; 1689 pb->holdbufsize = count + 2; 1690 } --- 45 unchanged lines hidden (view full) --- 1736 memcpy (pb->holdbuf + pb->holdsize, bytes, nread); 1737 inbuf = pb->holdbuf + 2; 1738 } 1739 1740 if (count <= sizeof stackoutbuf) 1741 outbuf = stackoutbuf; 1742 else 1743 { | 1683 if (n == NULL) 1684 { 1685 (*pb->buf->memory_error) (pb->buf); 1686 return ENOMEM; 1687 } 1688 pb->holdbuf = n; 1689 pb->holdbufsize = count + 2; 1690 } --- 45 unchanged lines hidden (view full) --- 1736 memcpy (pb->holdbuf + pb->holdsize, bytes, nread); 1737 inbuf = pb->holdbuf + 2; 1738 } 1739 1740 if (count <= sizeof stackoutbuf) 1741 outbuf = stackoutbuf; 1742 else 1743 { |
1744 outbuf = malloc (count); | 1744 outbuf = xmalloc (count); |
1745 if (outbuf == NULL) 1746 { 1747 (*pb->buf->memory_error) (pb->buf); 1748 return ENOMEM; 1749 } 1750 } 1751 1752 status = (*pb->inpfn) (pb->fnclosure, inbuf, outbuf, count); --- 55 unchanged lines hidden (view full) --- 1808 char inbuf[BUFFER_DATA_SIZE + 2]; 1809 char stack_outbuf[BUFFER_DATA_SIZE + PACKET_SLOP + 4]; 1810 struct buffer_data *outdata; 1811 char *outbuf; 1812 int size, status, translated; 1813 1814 if (have > BUFFER_DATA_SIZE) 1815 { | 1745 if (outbuf == NULL) 1746 { 1747 (*pb->buf->memory_error) (pb->buf); 1748 return ENOMEM; 1749 } 1750 } 1751 1752 status = (*pb->inpfn) (pb->fnclosure, inbuf, outbuf, count); --- 55 unchanged lines hidden (view full) --- 1808 char inbuf[BUFFER_DATA_SIZE + 2]; 1809 char stack_outbuf[BUFFER_DATA_SIZE + PACKET_SLOP + 4]; 1810 struct buffer_data *outdata; 1811 char *outbuf; 1812 int size, status, translated; 1813 1814 if (have > BUFFER_DATA_SIZE) 1815 { |
1816 /* It would be easy to malloc a buffer, but I don't think this | 1816 /* It would be easy to xmalloc a buffer, but I don't think this |
1817 case can ever arise. */ 1818 abort (); 1819 } 1820 1821 inbuf[0] = (have >> 8) & 0xff; 1822 inbuf[1] = have & 0xff; 1823 memcpy (inbuf + 2, data, have); 1824 --- 94 unchanged lines hidden --- | 1817 case can ever arise. */ 1818 abort (); 1819 } 1820 1821 inbuf[0] = (have >> 8) & 0xff; 1822 inbuf[1] = have & 0xff; 1823 memcpy (inbuf + 2, data, have); 1824 --- 94 unchanged lines hidden --- |