* Execute a command in a pipe and read the first line from it. */
| 360 | * Execute a command in a pipe and read the first line from it. |
| 361 | */ |
| 362 | char * |
| 363 | pipe_read_line(char *cmd, char *line, int maxsize) |
| 364 | { |
| 365 | FILE *pgver; |
| 366 | |
| 367 | /* flush output buffers in case popen does not... */ |
| 368 | fflush(stdout); |
| 369 | fflush(stderr); |
| 370 | |
| 371 | errno = 0; |
| 372 | if ((pgver = popen(cmd, "r")) == NULL) |
| 373 | { |
| 374 | perror("popen failure"); |
| 375 | return NULL; |
| 376 | } |
| 377 | |
| 378 | errno = 0; |
| 379 | if (fgets(line, maxsize, pgver) == NULL) |
| 380 | { |
| 381 | if (feof(pgver)) |
| 382 | fprintf(stderr, "no data was returned by command \"%s\"\n", cmd); |
| 383 | else |
| 384 | perror("fgets failure"); |
| 385 | pclose(pgver); /* no error checking */ |
| 386 | return NULL; |
| 387 | } |
| 388 | |
| 389 | if (pclose_check(pgver)) |
| 390 | return NULL; |
| 391 | |
| 392 | return line; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | /* |
no test coverage detected