| 1234 | Return true if successful. */ |
| 1235 | |
| 1236 | static bool |
| 1237 | cut_file (char const *file, void (*cut_stream) (FILE *)) |
| 1238 | { |
| 1239 | FILE *stream; |
| 1240 | |
| 1241 | if (streq (file, "-")) |
| 1242 | { |
| 1243 | have_read_stdin = true; |
| 1244 | stream = stdin; |
| 1245 | assume (stream); /* Pacify GCC bug#109613. */ |
| 1246 | } |
| 1247 | else |
| 1248 | { |
| 1249 | stream = fopen (file, "r"); |
| 1250 | if (stream == NULL) |
| 1251 | { |
| 1252 | error (0, errno, "%s", quotef (file)); |
| 1253 | return false; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | fadvise (stream, FADVISE_SEQUENTIAL); |
| 1258 | |
| 1259 | cut_stream (stream); |
| 1260 | |
| 1261 | int err = errno; |
| 1262 | if (!ferror (stream)) |
| 1263 | err = 0; |
| 1264 | if (streq (file, "-")) |
| 1265 | clearerr (stream); /* Also clear EOF. */ |
| 1266 | else if (fclose (stream) == EOF) |
| 1267 | err = errno; |
| 1268 | if (err) |
| 1269 | { |
| 1270 | error (0, err, "%s", quotef (file)); |
| 1271 | return false; |
| 1272 | } |
| 1273 | return true; |
| 1274 | } |
| 1275 | |
| 1276 | int |
| 1277 | main (int argc, char **argv) |