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

Function mbbuf_topup

gl/lib/mbbuf.h:81–115  ·  view source on GitHub ↗

Fill the input buffer with at least MCEL_LEN_MAX bytes if possible. Return the number of bytes available from the current offset. At end of file, MBBUF.EOF is set, and zero will eventually be returned. Note feof() will _NOT_ be set on the MBBUF.FP. */

Source from the content-addressed store, hash-verified

79 At end of file, MBBUF.EOF is set, and zero will eventually be returned.
80 Note feof() will _NOT_ be set on the MBBUF.FP. */
81MBBUF_INLINE idx_t
82mbbuf_topup (mbbuf_t *mbbuf)
83{
84 idx_t available = mbbuf_avail (mbbuf);
85
86 if (available < MCEL_LEN_MAX && ! mbbuf->eof)
87 {
88 idx_t start;
89 if (!(0 < available))
90 start = 0;
91 else
92 {
93 memmove (mbbuf->buffer, mbbuf->buffer + mbbuf->offset, available);
94 start = available;
95 }
96 ssize_t read_ret = read (fileno (mbbuf->fp), mbbuf->buffer + start,
97 mbbuf->size - start);
98 if (read_ret < 0)
99 {
100 fseterr (mbbuf->fp);
101 mbbuf->eof = true; /* Avoid any more reads(). */
102 mbbuf->length = start;
103 }
104 else
105 {
106 mbbuf->eof = read_ret == 0;
107 mbbuf->length = read_ret + start;
108 }
109
110 mbbuf->offset = 0;
111 available = mbbuf_avail (mbbuf);
112 }
113
114 return available;
115}
116
117/* Fill the input buffer enough to scan the next character if possible.
118 Return the number of bytes available from the current offset. */

Callers 2

mbbuf_fillFunction · 0.85
cut_fields_bytesearchFunction · 0.85

Calls 1

mbbuf_availFunction · 0.85

Tested by

no test coverage detected