Returns the captured text (heap, "" when nothing was written) or NULL when * the capture never engaged. */
| 771 | /* Returns the captured text (heap, "" when nothing was written) or NULL when |
| 772 | * the capture never engaged. */ |
| 773 | static char *cli_fd_capture_end(cli_fd_capture_t *capture) { |
| 774 | fflush(capture->stream); |
| 775 | if (capture->saved_fd >= 0) { |
| 776 | (void)dup2(capture->saved_fd, capture->target_fd); |
| 777 | close(capture->saved_fd); |
| 778 | capture->saved_fd = -1; |
| 779 | } |
| 780 | char *text = NULL; |
| 781 | if (capture->file) { |
| 782 | if (capture->redirected) { |
| 783 | rewind(capture->file); |
| 784 | size_t capacity = 65536U; |
| 785 | text = calloc(1U, capacity); |
| 786 | if (text) { |
| 787 | size_t count = fread(text, 1U, capacity - 1U, capture->file); |
| 788 | text[count] = '\0'; |
| 789 | } |
| 790 | } |
| 791 | fclose(capture->file); |
| 792 | capture->file = NULL; |
| 793 | } |
| 794 | return text; |
| 795 | } |
| 796 | #endif /* !_WIN32 -- POSIX-only fd-capture helpers (#2110) */ |
| 797 | |
| 798 | /* Mandatory-daemon activation guard fixture. The production path uses the |
no test coverage detected