| 150 | If START is null, just flush the buffer. */ |
| 151 | |
| 152 | static void |
| 153 | output (char const *start, char const *past_end) |
| 154 | { |
| 155 | static char buffer[WRITESIZE]; |
| 156 | static size_t bytes_in_buffer = 0; |
| 157 | size_t bytes_to_add = past_end - start; |
| 158 | size_t bytes_available = WRITESIZE - bytes_in_buffer; |
| 159 | |
| 160 | if (!start) |
| 161 | { |
| 162 | if (full_write (STDOUT_FILENO, buffer, bytes_in_buffer) |
| 163 | != bytes_in_buffer) |
| 164 | write_error (); |
| 165 | bytes_in_buffer = 0; |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | /* Write out as many full buffers as possible. */ |
| 170 | while (bytes_to_add >= bytes_available) |
| 171 | { |
| 172 | memcpy (buffer + bytes_in_buffer, start, bytes_available); |
| 173 | bytes_to_add -= bytes_available; |
| 174 | start += bytes_available; |
| 175 | if (full_write (STDOUT_FILENO, buffer, WRITESIZE) != WRITESIZE) |
| 176 | write_error (); |
| 177 | bytes_in_buffer = 0; |
| 178 | bytes_available = WRITESIZE; |
| 179 | } |
| 180 | |
| 181 | memcpy (buffer + bytes_in_buffer, start, bytes_to_add); |
| 182 | bytes_in_buffer += bytes_to_add; |
| 183 | } |
| 184 | |
| 185 | /* Print in reverse the file open on descriptor FD for reading FILE. |
| 186 | The file is already positioned at FILE_POS, which should be near its end. |
no test coverage detected