|
|
61d8f4 |
diff --git a/src/cmd/ksh93/include/io.h b/src/cmd/ksh93/include/io.h
|
|
|
61d8f4 |
--- a/src/cmd/ksh93/include/io.h
|
|
|
61d8f4 |
+++ b/src/cmd/ksh93/include/io.h
|
|
|
61d8f4 |
@@ -79,7 +79,7 @@ extern Sfio_t *sh_iostream(Shell_t*,int);
|
|
|
61d8f4 |
extern int sh_redirect(Shell_t*,struct ionod*,int);
|
|
|
61d8f4 |
extern void sh_iosave(Shell_t *, int,int,char*);
|
|
|
61d8f4 |
extern int safefdnumber(Shell_t* shp, int sfd);
|
|
|
61d8f4 |
-extern int sh_iovalidfd(Shell_t*, int);
|
|
|
61d8f4 |
+extern bool sh_iovalidfd(Shell_t*, int);
|
|
|
61d8f4 |
extern int sh_inuse(Shell_t*, int);
|
|
|
61d8f4 |
extern void sh_iounsave(Shell_t*);
|
|
|
61d8f4 |
extern void iounpipe(Shell_t*);
|
|
|
61d8f4 |
diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c
|
|
|
61d8f4 |
--- a/src/cmd/ksh93/sh/io.c
|
|
|
61d8f4 |
+++ b/src/cmd/ksh93/sh/io.c
|
|
|
61d8f4 |
@@ -403,38 +403,50 @@ static short filemapsize;
|
|
|
61d8f4 |
|
|
|
61d8f4 |
/* ======== input output and file copying ======== */
|
|
|
61d8f4 |
|
|
|
61d8f4 |
-int sh_iovalidfd(Shell_t *shp, int fd)
|
|
|
61d8f4 |
+bool sh_iovalidfd(Shell_t *shp, int fd)
|
|
|
61d8f4 |
{
|
|
|
61d8f4 |
Sfio_t **sftable = shp->sftable;
|
|
|
61d8f4 |
int max,n, **fdptrs = shp->fdptrs;
|
|
|
61d8f4 |
unsigned char *fdstatus = shp->fdstatus;
|
|
|
61d8f4 |
if(fd<0)
|
|
|
61d8f4 |
- return(0);
|
|
|
61d8f4 |
+ return(false);
|
|
|
61d8f4 |
if(fd < shp->gd->lim.open_max)
|
|
|
61d8f4 |
- return(1);
|
|
|
61d8f4 |
+ return(true);
|
|
|
61d8f4 |
max = strtol(astconf("OPEN_MAX",NiL,NiL),NiL,0);
|
|
|
61d8f4 |
if(fd >= max)
|
|
|
61d8f4 |
{
|
|
|
61d8f4 |
errno = EBADF;
|
|
|
61d8f4 |
- return(0);
|
|
|
61d8f4 |
+ return(false);
|
|
|
61d8f4 |
}
|
|
|
61d8f4 |
n = (fd+16)&~0xf;
|
|
|
61d8f4 |
- if(n > max)
|
|
|
61d8f4 |
- n = max;
|
|
|
61d8f4 |
+ if(n++ > max)
|
|
|
61d8f4 |
+ n = max+1;
|
|
|
61d8f4 |
max = shp->gd->lim.open_max;
|
|
|
61d8f4 |
- shp->sftable = (Sfio_t**)calloc((n+1)*(sizeof(int*)+sizeof(Sfio_t*)+1),1);
|
|
|
61d8f4 |
- if(max)
|
|
|
61d8f4 |
- memcpy(shp->sftable,sftable,max*sizeof(Sfio_t*));
|
|
|
61d8f4 |
+ shp->sftable = (Sfio_t**)calloc((n+1)*(sizeof(int*)+sizeof(Sfio_t*)+sizeof(*fdstatus)),1);
|
|
|
61d8f4 |
+
|
|
|
61d8f4 |
+ if(sftable)
|
|
|
61d8f4 |
+ {
|
|
|
61d8f4 |
+ --sftable;
|
|
|
61d8f4 |
+ if(max)
|
|
|
61d8f4 |
+ memcpy(shp->sftable,sftable,++max*sizeof(Sfio_t*));
|
|
|
61d8f4 |
+
|
|
|
61d8f4 |
+ }
|
|
|
61d8f4 |
+
|
|
|
61d8f4 |
shp->fdptrs = (int**)(&shp->sftable[n]);
|
|
|
61d8f4 |
if(max)
|
|
|
61d8f4 |
- memcpy(shp->fdptrs,fdptrs,max*sizeof(int*));
|
|
|
61d8f4 |
+ memcpy(shp->fdptrs,--fdptrs,max*sizeof(int*));
|
|
|
61d8f4 |
shp->fdstatus = (unsigned char*)(&shp->fdptrs[n]);
|
|
|
61d8f4 |
if(max)
|
|
|
61d8f4 |
- memcpy(shp->fdstatus,fdstatus,max);
|
|
|
61d8f4 |
+ memcpy(shp->fdstatus,--fdstatus,max);
|
|
|
61d8f4 |
+
|
|
|
61d8f4 |
if(sftable)
|
|
|
61d8f4 |
free((void*)sftable);
|
|
|
61d8f4 |
- shp->gd->lim.open_max = n;
|
|
|
61d8f4 |
- return(1);
|
|
|
61d8f4 |
+
|
|
|
61d8f4 |
+ shp->sftable++;
|
|
|
61d8f4 |
+ shp->fdptrs++;
|
|
|
61d8f4 |
+ shp->fdstatus++;
|
|
|
61d8f4 |
+ shp->gd->lim.open_max = n-1;
|
|
|
61d8f4 |
+ return(true);
|
|
|
61d8f4 |
}
|
|
|
61d8f4 |
|
|
|
61d8f4 |
int sh_inuse(Shell_t *shp, int fd)
|