/* Parsing multiple files */
-static struct fastbuf *
-bopen_safe(byte *name)
-{
- int fd = sh_open(name, O_RDONLY);
- if (fd < 0) {
- log(L_ERROR, "Cannot open %s", name);
- return NULL;
- }
- return bopen(name, O_RDONLY, 1<<14);
-}
-
static byte *
parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth)
{
msg = "The input command must be the last one on a line";
if (msg)
goto error;
- struct fastbuf *new_fb = bopen_safe(pars[0]);
+ struct fastbuf *new_fb = bopen_try(pars[0], O_RDONLY, 1<<14);
if (!new_fb) {
- msg = "Cannot open file";
+ msg = cf_printf("Cannot open file %s: %m", pars[0]);
goto error;
}
uns ll = line_num;
load_file(byte *file)
{
init_stack();
- struct fastbuf *fb = bopen_safe(file);
- if (!fb)
+ struct fastbuf *fb = bopen_try(file, O_RDONLY, 1<<14);
+ if (!fb) {
+ log(L_ERROR, "Cannot open %s: %m", file);
return 1;
+ }
byte *msg = parse_fastbuf(file, fb, 0);
bclose(fb);
int err = !!msg || done_stack();
die("Cannot set %s", optarg);
} else {
if (cf_load(optarg))
- die("Cannot load %s", optarg);
+ die("Cannot load config file %s", optarg);
}
} else {
/* unhandled option or end of options */
/* FastIO on standard files (specify buffer size 0 to enable mmaping) */
struct fastbuf *bopen(byte *name, uns mode, uns buflen);
+struct fastbuf *bopen_try(byte *name, uns mode, uns buflen);
struct fastbuf *bopen_tmp(uns buflen);
struct fastbuf *bfdopen(int fd, uns buflen);
struct fastbuf *bfdopen_shared(int fd, uns buflen);
}
struct fastbuf *
-bopen(byte *name, uns mode, uns buflen)
+bopen_try(byte *name, uns mode, uns buflen)
{
- struct fastbuf *b;
- int fd;
+ int fd = sh_open(name, mode, 0666);
+ if (fd < 0)
+ return NULL;
+ struct fastbuf *b = bfdopen_internal(fd, buflen, name);
+ if (mode & O_APPEND)
+ bfd_seek(b, 0, SEEK_END);
+ return b;
+}
+struct fastbuf *
+bopen(byte *name, uns mode, uns buflen)
+{
if (!buflen)
return bopen_mm(name, mode);
- fd = sh_open(name, mode, 0666);
- if (fd < 0)
+ struct fastbuf *b = bopen_try(name, mode, buflen);
+ if (!b)
die("Unable to %s file %s: %m",
(mode & O_CREAT) ? "create" : "open", name);
- b = bfdopen_internal(fd, buflen, name);
- if (mode & O_APPEND)
- bfd_seek(b, 0, SEEK_END);
return b;
}