| 315 | /* If FILE exists in HOME, print it to standard output, preceded by HEADER. */ |
| 316 | |
| 317 | static void |
| 318 | cat_file (char const *header, char const *home, char const *file) |
| 319 | { |
| 320 | char *full_name = file_name_concat (home, file, NULL); |
| 321 | int fd = open (full_name, O_RDONLY); |
| 322 | |
| 323 | if (0 <= fd) |
| 324 | { |
| 325 | idx_t header_len = strlen (header); |
| 326 | if (write (STDOUT_FILENO, header, header_len) != header_len) |
| 327 | write_error (); |
| 328 | |
| 329 | fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL); |
| 330 | |
| 331 | char buf[IO_BUFSIZE]; |
| 332 | for (ssize_t bytes_read; 0 < (bytes_read = read (fd, buf, sizeof buf));) |
| 333 | if (full_write (STDOUT_FILENO, buf, bytes_read) != bytes_read) |
| 334 | write_error (); |
| 335 | |
| 336 | close (fd); |
| 337 | } |
| 338 | |
| 339 | free (full_name); |
| 340 | } |
| 341 | |
| 342 | /* Display a verbose line of information about UTMP_ENT. */ |
| 343 |
no test coverage detected