428 |
setinputfile(const char *fname, int flags) |
setinputfile(const char *fname, int flags) |
429 |
{ |
{ |
430 |
int fd; |
int fd; |
|
int fd2; |
|
431 |
|
|
432 |
INTOFF; |
INTOFF; |
433 |
if ((fd = open(fname, O_RDONLY)) < 0) { |
if ((fd = open(fname, O_RDONLY)) < 0) { |
435 |
goto out; |
goto out; |
436 |
sh_error("Can't open %s", fname); |
sh_error("Can't open %s", fname); |
437 |
} |
} |
438 |
if (fd < 10) { |
if (fd < 10) |
439 |
fd2 = copyfd(fd, 10); |
fd = savefd(fd); |
|
close(fd); |
|
|
if (fd2 < 0) |
|
|
sh_error("Out of file descriptors"); |
|
|
fd = fd2; |
|
|
} |
|
440 |
setinputfd(fd, flags & INPUT_PUSH_FILE); |
setinputfd(fd, flags & INPUT_PUSH_FILE); |
441 |
out: |
out: |
442 |
INTON; |
INTON; |
452 |
void |
void |
453 |
setinputfd(int fd, int push) |
setinputfd(int fd, int push) |
454 |
{ |
{ |
|
(void) fcntl(fd, F_SETFD, FD_CLOEXEC); |
|
455 |
if (push) { |
if (push) { |
456 |
pushfile(); |
pushfile(); |
457 |
parsefile->buf = 0; |
parsefile->buf = 0; |