* xfopen() is the same as fopen(), but it die()s if the fopen() fails. */
| 355 | * xfopen() is the same as fopen(), but it die()s if the fopen() fails. |
| 356 | */ |
| 357 | FILE *xfopen(const char *path, const char *mode) |
| 358 | { |
| 359 | for (;;) { |
| 360 | FILE *fp = fopen(path, mode); |
| 361 | if (fp) |
| 362 | return fp; |
| 363 | if (errno == EINTR) |
| 364 | continue; |
| 365 | |
| 366 | if (*mode && mode[1] == '+') |
| 367 | die_errno(_("could not open '%s' for reading and writing"), path); |
| 368 | else if (*mode == 'w' || *mode == 'a') |
| 369 | die_errno(_("could not open '%s' for writing"), path); |
| 370 | else |
| 371 | die_errno(_("could not open '%s' for reading"), path); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | FILE *xfdopen(int fd, const char *mode) |
| 376 | { |