From 4daf75cefd7ca514d0188bae3adc8f61a63940e5 Mon Sep 17 00:00:00 2001 From: herbert Date: Mon, 28 Mar 2005 14:13:59 +1000 Subject: Generalise setinputfile for use in read_profile/readcmdfile. --- src/input.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/input.c') diff --git a/src/input.c b/src/input.c index 86d7578..8c874c6 100644 --- a/src/input.c +++ b/src/input.c @@ -433,15 +433,18 @@ popstring(void) * old input onto the stack first. */ -void -setinputfile(const char *fname, int push) +int +setinputfile(const char *fname, int flags) { int fd; int fd2; INTOFF; - if ((fd = open(fname, O_RDONLY)) < 0) + if ((fd = open(fname, O_RDONLY)) < 0) { + if (flags & INPUT_NOFILE_OK) + goto out; sh_error("Can't open %s", fname); + } if (fd < 10) { fd2 = copyfd(fd, 10); close(fd); @@ -449,8 +452,10 @@ setinputfile(const char *fname, int push) sh_error("Out of file descriptors"); fd = fd2; } - setinputfd(fd, push); + setinputfd(fd, flags & INPUT_PUSH_FILE); +out: INTON; + return fd; } -- cgit 1.4.1