• bump NUFILE and FDBASE, allowing for more than 10 fds used by scripts

• change the code to accept more than a single digit for an fd
This commit is contained in:
tg
2008-07-09 21:32:45 +00:00
parent 943446cadf
commit ca7cd043db
6 changed files with 84 additions and 45 deletions

58
main.c
View File

@ -1,3 +1,4 @@
#include <err.h>
/* $OpenBSD: main.c,v 1.44 2008/07/05 07:25:18 djm Exp $ */
/* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */
@ -13,7 +14,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.99 2008/07/08 22:28:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.100 2008/07/09 21:32:43 tg Exp $");
extern char **environ;
@ -1007,32 +1008,35 @@ check_fd(const char *name, int mode, const char **emsgp)
{
int fd, fl;
if (ksh_isdigit(name[0]) && !name[1]) {
if ((fl = fcntl(fd = name[0] - '0', F_GETFL, 0)) < 0) {
if (emsgp)
*emsgp = "bad file descriptor";
return -1;
}
fl &= O_ACCMODE;
/* X_OK is a kludge to disable this check for dups (x<&1):
* historical shells never did this check (XXX don't know what
* posix has to say).
*/
if (!(mode & X_OK) && fl != O_RDWR &&
(((mode & R_OK) && fl != O_RDONLY) ||
((mode & W_OK) && fl != O_WRONLY))) {
if (emsgp)
*emsgp = (fl == O_WRONLY) ?
"fd not open for reading" :
"fd not open for writing";
return -1;
}
return fd;
} else if (name[0] == 'p' && !name[1])
return coproc_getfd(mode, emsgp);
if (emsgp)
*emsgp = "illegal file descriptor name";
return -1;
if (name[0] == 'p' && !name[1])
return (coproc_getfd(mode, emsgp));
for (fd = 0; ksh_isdigit(*name); ++name)
fd = (fd * 10) + *name - '0';
if (*name || fd >= FDBASE) {
if (emsgp)
*emsgp = "illegal file descriptor name";
return (-1);
}
if ((fl = fcntl(fd, F_GETFL, 0)) < 0) {
if (emsgp)
*emsgp = "bad file descriptor";
return (-1);
}
fl &= O_ACCMODE;
/* X_OK is a kludge to disable this check for dups (x<&1):
* historical shells never did this check (XXX don't know what
* posix has to say).
*/
if (!(mode & X_OK) && fl != O_RDWR && (
((mode & R_OK) && fl != O_RDONLY) ||
((mode & W_OK) && fl != O_WRONLY))) {
if (emsgp)
*emsgp = (fl == O_WRONLY) ?
"fd not open for reading" :
"fd not open for writing";
return (-1);
}
return (fd);
}
/* Called once from main */