fclose() might overwrite the errno value from fprintf, causing us to
return success when we shouldn't. Record the errno value at the time
of the fprintf failure.
if (file == NULL)
return errno;
pid = (unsigned long) getpid();
- st1 = fprintf(file, "%ld\n", pid);
- st2 = fclose(file);
- return (st1 < 0 || st2 == EOF) ? errno : 0;
+ st1 = (fprintf(file, "%ld\n", pid) < 0) ? errno : 0;
+ st2 = (fclose(file) == EOF) ? errno : 0;
+ return st1 ? st1 : st2;
}
/* XXX yuck. the signal handlers need this */