Should use 'pclose' instead of 'fclose' (although fclose happens
to work because of glibc internals).
The result of pclose is the exit status of the command, so we
need to test this is != 0.
for (i = 0; lines[i] != NULL; ++i) {
if (fprintf (fp, "%s\n", lines[i]) < 0) {
reply_with_perror (buf);
- fclose (fp);
+ pclose (fp);
return -1;
}
}
- if (fclose (fp) == EOF) {
- reply_with_perror (buf);
- fclose (fp);
+ if (pclose (fp) != 0) {
+ reply_with_error ("%s: external command failed", buf);
return -1;
}