blob: e596f074f19e024a8258a52a482845ad98477b54 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include "../util.h"
int
fshut(FILE *fp, const char *fname)
{
int ret = 0;
/* fflush() is undefined for input streams by ISO C,
* but not POSIX 2008 if you ignore ISO C overrides.
* Leave it unchecked and rely on the following
* functions to detect errors.
*/
fflush(fp);
if (ferror(fp) && !ret) {
weprintf("ferror %s:", fname);
ret = 1;
}
if (fclose(fp) && !ret) {
weprintf("fclose %s:", fname);
ret = 1;
}
return ret;
}
void
enfshut(int status, FILE *fp, const char *fname)
{
if (fshut(fp, fname))
exit(status);
}
void
efshut(FILE *fp, const char *fname)
{
enfshut(1, fp, fname);
}
|