MCPcopy Create free account
hub / github.com/coreutils/coreutils / cat

Function cat

src/cat.c:229–515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227 an explicit test for buffer end unnecessary. */
228
229static bool
230cat (char *inbuf, idx_t insize, char *outbuf, idx_t outsize,
231 bool show_nonprinting, bool show_tabs, bool number, bool number_nonblank,
232 bool show_ends, bool squeeze_blank)
233{
234 /* Last character read from the input buffer. */
235 unsigned char ch;
236
237 /* Determines how many consecutive newlines there have been in the
238 input. 0 newlines makes NEWLINES -1, 1 newline makes NEWLINES 1,
239 etc. Initially 0 to indicate that we are at the beginning of a
240 new line. The "state" of the procedure is determined by
241 NEWLINES. */
242 int newlines = newlines2;
243
244#ifdef FIONREAD
245 /* If nonzero, use the FIONREAD ioctl, as an optimization.
246 (On Ultrix, it is not supported on NFS file systems.) */
247 bool use_fionread = true;
248#endif
249
250 /* The inbuf pointers are initialized so that BPIN > EOB, and thereby input
251 is read immediately. */
252
253 /* Pointer to the first non-valid byte in the input buffer, i.e., the
254 current end of the buffer. */
255 char *eob = inbuf;
256
257 /* Pointer to the next character in the input buffer. */
258 char *bpin = eob + 1;
259
260 /* Pointer to the position where the next character shall be written. */
261 char *bpout = outbuf;
262
263 while (true)
264 {
265 do
266 {
267 /* Write if there are at least OUTSIZE bytes in OUTBUF. */
268
269 if (outbuf + outsize <= bpout)
270 {
271 char *wp = outbuf;
272 idx_t remaining_bytes;
273 do
274 {
275 if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
276 write_error ();
277 wp += outsize;
278 remaining_bytes = bpout - wp;
279 }
280 while (outsize <= remaining_bytes);
281
282 /* Move the remaining bytes to the beginning of the
283 buffer. */
284
285 memmove (outbuf, wp, remaining_bytes);
286 bpout = outbuf + remaining_bytes;

Callers 1

mainFunction · 0.85

Calls 3

write_errorFunction · 0.85
write_pendingFunction · 0.85
next_line_numFunction · 0.85

Tested by

no test coverage detected