Capture per-tool help using the same tmpfile+dup2 idiom as config-command * output above. This stays portable to the MinGW test leg. */
| 17269 | /* Capture per-tool help using the same tmpfile+dup2 idiom as config-command |
| 17270 | * output above. This stays portable to the MinGW test leg. */ |
| 17271 | static int cli_tool_help_capture(const char *tool_name, char *out, size_t cap) { |
| 17272 | out[0] = '\0'; |
| 17273 | FILE *capture = tmpfile(); |
| 17274 | int saved = capture ? dup(fileno(stdout)) : -1; |
| 17275 | if (!capture || saved < 0) { |
| 17276 | if (capture) |
| 17277 | fclose(capture); |
| 17278 | if (saved >= 0) |
| 17279 | close(saved); |
| 17280 | return -1000; |
| 17281 | } |
| 17282 | fflush(stdout); |
| 17283 | if (dup2(fileno(capture), fileno(stdout)) < 0) { |
| 17284 | fclose(capture); |
| 17285 | close(saved); |
| 17286 | return -1000; |
| 17287 | } |
| 17288 | int rc = cbm_cli_print_tool_help(tool_name); |
| 17289 | fflush(stdout); |
| 17290 | (void)dup2(saved, fileno(stdout)); |
| 17291 | close(saved); |
| 17292 | rewind(capture); |
| 17293 | size_t got = fread(out, 1, cap - 1, capture); |
| 17294 | out[got] = '\0'; |
| 17295 | fclose(capture); |
| 17296 | return rc; |
| 17297 | } |
| 17298 | |
| 17299 | /* Per-tool --help returns 0 for a known tool, -1 for an unknown one, and |
| 17300 | * surfaces schema choices/defaults rather than flattening every flag to its |
no test coverage detected