-rw-r--r-- | rsync/buf.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/rsync/buf.c b/rsync/buf.c index 2814583..c978fff 100644 --- a/rsync/buf.c +++ b/rsync/buf.c | |||
@@ -51,147 +51,149 @@ | |||
51 | #include "rsync.h" | 51 | #include "rsync.h" |
52 | #include "trace.h" | 52 | #include "trace.h" |
53 | #include "buf.h" | 53 | #include "buf.h" |
54 | #include "util.h" | 54 | #include "util.h" |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * File IO buffer sizes. | 57 | * File IO buffer sizes. |
58 | */ | 58 | */ |
59 | int rs_inbuflen = 16000, rs_outbuflen = 16000; | 59 | int rs_inbuflen = 16000, rs_outbuflen = 16000; |
60 | 60 | ||
61 | 61 | ||
62 | struct rs_filebuf { | 62 | struct rs_filebuf { |
63 | FILE *f; | 63 | FILE *f; |
64 | char *buf; | 64 | char *buf; |
65 | size_t buf_len; | 65 | size_t buf_len; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | 68 | ||
69 | 69 | ||
70 | rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len) | 70 | rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len) |
71 | { | 71 | { |
72 | rs_filebuf_t *pf = rs_alloc_struct(rs_filebuf_t); | 72 | rs_filebuf_t *pf = rs_alloc_struct(rs_filebuf_t); |
73 | 73 | ||
74 | pf->buf = rs_alloc(buf_len, "file buffer"); | 74 | pf->buf = rs_alloc(buf_len, "file buffer"); |
75 | pf->buf_len = buf_len; | 75 | pf->buf_len = buf_len; |
76 | pf->f = f; | 76 | pf->f = f; |
77 | 77 | ||
78 | return pf; | 78 | return pf; |
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | void rs_filebuf_free(rs_filebuf_t *fb) | 82 | void rs_filebuf_free(rs_filebuf_t *fb) |
83 | { | 83 | { |
84 | if ( fb->buf ) | 84 | if ( fb->buf ) |
85 | free ( fb->buf ); | 85 | free ( fb->buf ); |
86 | rs_bzero(fb, sizeof *fb); | 86 | rs_bzero(fb, sizeof *fb); |
87 | free(fb); | 87 | free(fb); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | /* | 91 | /* |
92 | * If the stream has no more data available, read some from F into | 92 | * If the stream has no more data available, read some from F into |
93 | * BUF, and let the stream use that. On return, SEEN_EOF is true if | 93 | * BUF, and let the stream use that. On return, SEEN_EOF is true if |
94 | * the end of file has passed into the stream. | 94 | * the end of file has passed into the stream. |
95 | */ | 95 | */ |
96 | rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf, | 96 | rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf, |
97 | void *opaque) | 97 | void *opaque) |
98 | { | 98 | { |
99 | job=job; | ||
99 | int len; | 100 | int len; |
100 | rs_filebuf_t *fb = (rs_filebuf_t *) opaque; | 101 | rs_filebuf_t *fb = (rs_filebuf_t *) opaque; |
101 | FILE *f = fb->f; | 102 | FILE *f = fb->f; |
102 | 103 | ||
103 | /* This is only allowed if either the buf has no input buffer | 104 | /* This is only allowed if either the buf has no input buffer |
104 | * yet, or that buffer could possibly be BUF. */ | 105 | * yet, or that buffer could possibly be BUF. */ |
105 | if (buf->next_in != NULL) { | 106 | if (buf->next_in != NULL) { |
106 | assert(buf->avail_in <= fb->buf_len); | 107 | assert(buf->avail_in <= fb->buf_len); |
107 | assert(buf->next_in >= fb->buf); | 108 | assert(buf->next_in >= fb->buf); |
108 | assert(buf->next_in <= fb->buf + fb->buf_len); | 109 | assert(buf->next_in <= fb->buf + fb->buf_len); |
109 | } else { | 110 | } else { |
110 | assert(buf->avail_in == 0); | 111 | assert(buf->avail_in == 0); |
111 | } | 112 | } |
112 | 113 | ||
113 | if (buf->eof_in || (buf->eof_in = feof(f))) { | 114 | if (buf->eof_in || (buf->eof_in = feof(f))) { |
114 | rs_trace("seen end of file on input"); | 115 | rs_trace("seen end of file on input"); |
115 | buf->eof_in = 1; | 116 | buf->eof_in = 1; |
116 | return RS_DONE; | 117 | return RS_DONE; |
117 | } | 118 | } |
118 | 119 | ||
119 | if (buf->avail_in) | 120 | if (buf->avail_in) |
120 | /* Still some data remaining. Perhaps we should read | 121 | /* Still some data remaining. Perhaps we should read |
121 | anyhow? */ | 122 | anyhow? */ |
122 | return RS_DONE; | 123 | return RS_DONE; |
123 | 124 | ||
124 | len = fread(fb->buf, 1, fb->buf_len, f); | 125 | len = fread(fb->buf, 1, fb->buf_len, f); |
125 | if (len < 0) { | 126 | if (len < 0) { |
126 | if (ferror(f)) { | 127 | if (ferror(f)) { |
127 | rs_error("error filling buf from file: %s", | 128 | rs_error("error filling buf from file: %s", |
128 | strerror(errno)); | 129 | strerror(errno)); |
129 | return RS_IO_ERROR; | 130 | return RS_IO_ERROR; |
130 | } else { | 131 | } else { |
131 | rs_error("no error bit, but got %d return when trying to read", | 132 | rs_error("no error bit, but got %d return when trying to read", |
132 | len); | 133 | len); |
133 | return RS_IO_ERROR; | 134 | return RS_IO_ERROR; |
134 | } | 135 | } |
135 | } | 136 | } |
136 | buf->avail_in = len; | 137 | buf->avail_in = len; |
137 | buf->next_in = fb->buf; | 138 | buf->next_in = fb->buf; |
138 | 139 | ||
139 | return RS_DONE; | 140 | return RS_DONE; |
140 | } | 141 | } |
141 | 142 | ||
142 | 143 | ||
143 | /* | 144 | /* |
144 | * The buf is already using BUF for an output buffer, and probably | 145 | * The buf is already using BUF for an output buffer, and probably |
145 | * contains some buffered output now. Write this out to F, and reset | 146 | * contains some buffered output now. Write this out to F, and reset |
146 | * the buffer cursor. | 147 | * the buffer cursor. |
147 | */ | 148 | */ |
148 | rs_result rs_outfilebuf_drain(rs_job_t *job, rs_buffers_t *buf, void *opaque) | 149 | rs_result rs_outfilebuf_drain(rs_job_t *job, rs_buffers_t *buf, void *opaque) |
149 | { | 150 | { |
151 | job=job; | ||
150 | int present; | 152 | int present; |
151 | rs_filebuf_t *fb = (rs_filebuf_t *) opaque; | 153 | rs_filebuf_t *fb = (rs_filebuf_t *) opaque; |
152 | FILE *f = fb->f; | 154 | FILE *f = fb->f; |
153 | 155 | ||
154 | /* This is only allowed if either the buf has no output buffer | 156 | /* This is only allowed if either the buf has no output buffer |
155 | * yet, or that buffer could possibly be BUF. */ | 157 | * yet, or that buffer could possibly be BUF. */ |
156 | if (buf->next_out == NULL) { | 158 | if (buf->next_out == NULL) { |
157 | assert(buf->avail_out == 0); | 159 | assert(buf->avail_out == 0); |
158 | 160 | ||
159 | buf->next_out = fb->buf; | 161 | buf->next_out = fb->buf; |
160 | buf->avail_out = fb->buf_len; | 162 | buf->avail_out = fb->buf_len; |
161 | 163 | ||
162 | return RS_DONE; | 164 | return RS_DONE; |
163 | } | 165 | } |
164 | 166 | ||
165 | assert(buf->avail_out <= fb->buf_len); | 167 | assert(buf->avail_out <= fb->buf_len); |
166 | assert(buf->next_out >= fb->buf); | 168 | assert(buf->next_out >= fb->buf); |
167 | assert(buf->next_out <= fb->buf + fb->buf_len); | 169 | assert(buf->next_out <= fb->buf + fb->buf_len); |
168 | 170 | ||
169 | present = buf->next_out - fb->buf; | 171 | present = buf->next_out - fb->buf; |
170 | if (present > 0) { | 172 | if (present > 0) { |
171 | int result; | 173 | int result; |
172 | 174 | ||
173 | assert(present > 0); | 175 | assert(present > 0); |
174 | 176 | ||
175 | result = fwrite(fb->buf, 1, present, f); | 177 | result = fwrite(fb->buf, 1, present, f); |
176 | if (present != result) { | 178 | if (present != result) { |
177 | rs_error("error draining buf to file: %s", | 179 | rs_error("error draining buf to file: %s", |
178 | strerror(errno)); | 180 | strerror(errno)); |
179 | return RS_IO_ERROR; | 181 | return RS_IO_ERROR; |
180 | } | 182 | } |
181 | 183 | ||
182 | buf->next_out = fb->buf; | 184 | buf->next_out = fb->buf; |
183 | buf->avail_out = fb->buf_len; | 185 | buf->avail_out = fb->buf_len; |
184 | } | 186 | } |
185 | 187 | ||
186 | return RS_DONE; | 188 | return RS_DONE; |
187 | } | 189 | } |
188 | 190 | ||
189 | 191 | ||
190 | /** | 192 | /** |
191 | * Default copy implementation that retrieves a part of a stdio file. | 193 | * Default copy implementation that retrieves a part of a stdio file. |
192 | */ | 194 | */ |
193 | rs_result rs_file_copy_cb(void *arg, off_t pos, size_t *len, void **buf) | 195 | rs_result rs_file_copy_cb(void *arg, off_t pos, size_t *len, void **buf) |
194 | { | 196 | { |
195 | int got; | 197 | int got; |
196 | FILE *f = (FILE *) arg; | 198 | FILE *f = (FILE *) arg; |
197 | 199 | ||