Deleted Added
full compact
buffer.c (32785) buffer.c (34461)
1/* Code for the buffer data structure. */
2
3#include <assert.h>
4#include "cvs.h"
5#include "buffer.h"
6
7#if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT)
8
9/* OS/2 doesn't have EIO. FIXME: this whole notion of turning
10 a different error into EIO strikes me as pretty dubious. */
11#if !defined (EIO)
12#define EIO EBADPOS
13#endif
14
15/* Linked list of available buffer_data structures. */
16static struct buffer_data *free_buffer_data;
17
18/* Local functions. */
1/* Code for the buffer data structure. */
2
3#include <assert.h>
4#include "cvs.h"
5#include "buffer.h"
6
7#if defined (SERVER_SUPPORT) || defined (CLIENT_SUPPORT)
8
9/* OS/2 doesn't have EIO. FIXME: this whole notion of turning
10 a different error into EIO strikes me as pretty dubious. */
11#if !defined (EIO)
12#define EIO EBADPOS
13#endif
14
15/* Linked list of available buffer_data structures. */
16static struct buffer_data *free_buffer_data;
17
18/* Local functions. */
19static void buf_default_memory_error PROTO ((struct buffer *));
19static void allocate_buffer_datas PROTO((void));
20static struct buffer_data *get_buffer_data PROTO((void));
21
22/* Initialize a buffer structure. */
23
24struct buffer *
25buf_initialize (input, output, flush, block, shutdown, memory, closure)
26 int (*input) PROTO((void *, char *, int, int, int *));

--- 10 unchanged lines hidden (view full) ---

37 buf->data = NULL;
38 buf->last = NULL;
39 buf->nonblocking = 0;
40 buf->input = input;
41 buf->output = output;
42 buf->flush = flush;
43 buf->block = block;
44 buf->shutdown = shutdown;
20static void allocate_buffer_datas PROTO((void));
21static struct buffer_data *get_buffer_data PROTO((void));
22
23/* Initialize a buffer structure. */
24
25struct buffer *
26buf_initialize (input, output, flush, block, shutdown, memory, closure)
27 int (*input) PROTO((void *, char *, int, int, int *));

--- 10 unchanged lines hidden (view full) ---

38 buf->data = NULL;
39 buf->last = NULL;
40 buf->nonblocking = 0;
41 buf->input = input;
42 buf->output = output;
43 buf->flush = flush;
44 buf->block = block;
45 buf->shutdown = shutdown;
45 buf->memory_error = memory;
46 buf->memory_error = memory ? memory : buf_default_memory_error;
46 buf->closure = closure;
47 return buf;
48}
49
47 buf->closure = closure;
48 return buf;
49}
50
51/* Free a buffer structure. */
52
53void
54buf_free (buf)
55 struct buffer *buf;
56{
57 if (buf->data != NULL)
58 {
59 buf->last->next = free_buffer_data;
60 free_buffer_data = buf->data;
61 }
62 free (buf);
63}
64
50/* Initialize a buffer structure which is not to be used for I/O. */
51
52struct buffer *
53buf_nonio_initialize (memory)
54 void (*memory) PROTO((struct buffer *));
55{
56 return (buf_initialize
57 ((int (*) PROTO((void *, char *, int, int, int *))) NULL,
58 (int (*) PROTO((void *, const char *, int, int *))) NULL,
59 (int (*) PROTO((void *))) NULL,
60 (int (*) PROTO((void *, int))) NULL,
61 (int (*) PROTO((void *))) NULL,
62 memory,
63 (void *) NULL));
64}
65
65/* Initialize a buffer structure which is not to be used for I/O. */
66
67struct buffer *
68buf_nonio_initialize (memory)
69 void (*memory) PROTO((struct buffer *));
70{
71 return (buf_initialize
72 ((int (*) PROTO((void *, char *, int, int, int *))) NULL,
73 (int (*) PROTO((void *, const char *, int, int *))) NULL,
74 (int (*) PROTO((void *))) NULL,
75 (int (*) PROTO((void *, int))) NULL,
76 (int (*) PROTO((void *))) NULL,
77 memory,
78 (void *) NULL));
79}
80
81/* Default memory error handler. */
82
83static void
84buf_default_memory_error (buf)
85 struct buffer *buf;
86{
87 error (1, 0, "out of memory");
88}
89
66/* Allocate more buffer_data structures. */
67
68static void
69allocate_buffer_datas ()
70{
71 struct buffer_data *alc;
72 char *space;
73 int i;

--- 391 unchanged lines hidden (view full) ---

465 if (buf->data == NULL)
466 buf->data = data;
467 else
468 buf->last->next = data;
469 buf->last = last;
470 }
471}
472
90/* Allocate more buffer_data structures. */
91
92static void
93allocate_buffer_datas ()
94{
95 struct buffer_data *alc;
96 char *space;
97 int i;

--- 391 unchanged lines hidden (view full) ---

489 if (buf->data == NULL)
490 buf->data = data;
491 else
492 buf->last->next = data;
493 buf->last = last;
494 }
495}
496
497/* Append the data on one buffer to another. This removes the data
498 from the source buffer. */
499
500void
501buf_append_buffer (to, from)
502 struct buffer *to;
503 struct buffer *from;
504{
505 buf_append_data (to, from->data, from->last);
506 from->data = NULL;
507 from->last = NULL;
508}
509
473/*
474 * Copy the contents of file F into buffer_data structures. We can't
475 * copy directly into an buffer, because we want to handle failure and
476 * succeess differently. Returns 0 on success, or -2 if out of
477 * memory, or a status code on error. Since the caller happens to
478 * know the size of the file, it is passed in as SIZE. On success,
479 * this function sets *RETP and *LASTP, which may be passed to
480 * buf_append_data.

--- 135 unchanged lines hidden (view full) ---

616 while (buf)
617 {
618 size += buf->size;
619 buf = buf->next;
620 }
621 return size;
622}
623
510/*
511 * Copy the contents of file F into buffer_data structures. We can't
512 * copy directly into an buffer, because we want to handle failure and
513 * succeess differently. Returns 0 on success, or -2 if out of
514 * memory, or a status code on error. Since the caller happens to
515 * know the size of the file, it is passed in as SIZE. On success,
516 * this function sets *RETP and *LASTP, which may be passed to
517 * buf_append_data.

--- 135 unchanged lines hidden (view full) ---

653 while (buf)
654 {
655 size += buf->size;
656 buf = buf->next;
657 }
658 return size;
659}
660
661/* Return the number of bytes in a buffer. */
662
663int
664buf_length (buf)
665 struct buffer *buf;
666{
667 return buf_chain_length (buf->data);
668}
669
624/*
625 * Read an arbitrary amount of data into an input buffer. The buffer
626 * will be in nonblocking mode, and we just grab what we can. Return
627 * 0 on success, or -1 on end of file, or -2 if out of memory, or an
628 * error code. If COUNTP is not NULL, *COUNTP is set to the number of
629 * bytes read.
630 */
631

--- 1097 unchanged lines hidden ---
670/*
671 * Read an arbitrary amount of data into an input buffer. The buffer
672 * will be in nonblocking mode, and we just grab what we can. Return
673 * 0 on success, or -1 on end of file, or -2 if out of memory, or an
674 * error code. If COUNTP is not NULL, *COUNTP is set to the number of
675 * bytes read.
676 */
677

--- 1097 unchanged lines hidden ---