summary refs log tree commit diff
path: root/src/input.c
diff options
context:
space:
mode:
authorherbert <herbert@gondor.apana.org.au>2005-03-28 14:13:59 +1000
committerHerbert Xu <herbert@gondor.apana.org.au>2005-09-26 18:33:05 +1000
commit4daf75cefd7ca514d0188bae3adc8f61a63940e5 (patch)
tree862bcb1ccf0f2808e593a8cda334e5d675db77f4 /src/input.c
parentRemoved some unnecessary inclusions of input.h. (diff)
downloaddash-4daf75cefd7ca514d0188bae3adc8f61a63940e5.tar.gz
dash-4daf75cefd7ca514d0188bae3adc8f61a63940e5.zip
Generalise setinputfile for use in read_profile/readcmdfile.
Diffstat (limited to '')
-rw-r--r--src/input.c13
1 files changed, 9 insertions, 4 deletions
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;
 }