Lines Matching defs:fd

204  * return <protocol>/<host>/<service> fd
215 int fd;
269 fd = getaddrinfo(s, t, &hint, &addr);
272 fd = -1;
274 if (fd)
276 if (fd != EAI_SYSTEM)
282 fd = -1;
293 while ((fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) >= 0)
295 if (server && !bind(fd, p->ai_addr, p->ai_addrlen) && !listen(fd, 5) || !server && !connect(fd, p->ai_addr, p->ai_addrlen))
297 close(fd);
298 fd = -1;
307 if (fd >= 0)
309 return fd;
360 int fd;
366 Sfoff_t end, cur =lseek(ep->fd, (Sfoff_t)0, SEEK_CUR);
371 end =lseek(ep->fd, (Sfoff_t)0, SEEK_END);
372 lseek(ep->fd, (Sfoff_t)0, SEEK_CUR);
400 int sh_iovalidfd(Shell_t *shp, int fd)
405 if(fd<0)
407 if(fd < shp->gd->lim.open_max)
410 if(fd >= max)
415 n = (fd+16)&~0xf;
434 int sh_inuse(Shell_t *shp, int fd)
436 return(fd < shp->gd->lim.open_max && shp->fdptrs[fd]);
505 * create or initialize a stream corresponding to descriptor <fd>
511 Sfio_t *sh_iostream(Shell_t *shp, register int fd)
514 register int status = sh_iocheckfd(shp,fd);
520 switch(fd)
543 if((iop = shp->sftable[fd]) && sffileno(iop)>=0)
549 else if(!(iop=sfnew((fd<=2?iop:0),bp,IOBSIZE,fd,flags)))
580 shp->sftable[fd] = iop;
589 register int fd;
591 fd = sfsetfd(sp,10);
593 fd = sh_fcntl(f2,F_DUPFD,10);
595 shp->infd = fd;
596 if(fd<0)
603 VALIDATE_FD(shp, fd);
606 if(shp->fdptrs[fd]=shp->fdptrs[f2])
608 if(f2==job.fd)
609 job.fd=fd;
610 *shp->fdptrs[fd] = fd;
613 shp->sftable[fd] = sp;
614 shp->fdstatus[fd] = shp->fdstatus[f2];
617 fcntl(fd,F_SETFD,FD_CLOEXEC);
618 shp->fdstatus[fd] |= IOCLEX;
683 int sh_close(register int fd)
688 if(fd<0)
691 VALIDATE_FD(shp, fd);
693 if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0)
696 (*fdnotify)(fd,SH_FDCLOSE);
697 r=close(fd);
699 if(fd>2)
700 shp->sftable[fd] = 0;
701 shp->fdstatus[fd] = IOCLOSE;
702 if(shp->fdptrs[fd])
703 *shp->fdptrs[fd] = -1;
704 shp->fdptrs[fd] = 0;
705 if(fd < 10)
706 shp->inuse_bits &= ~(1<<fd);
736 register int fd = -1;
763 fd = (int)strtol(path+8, &e, 10);
765 fd = -1;
774 fd = 2;
778 fd = 0;
782 fd = 1;
787 if (fd < 0)
789 if ((fd = inetopen(path+5, flags, onintr, shp)) < 0 && errno != ENOTDIR)
792 return(fd>=0);
793 if (fd >= 0)
800 if (fd >= 0)
813 fd = nfd;
816 if((mode=sh_iocheckfd(shp,fd))==IOCLOSE)
823 if((fd=dup(fd))<0)
836 while((fd = open(path, flags, mode)) < 0)
849 VALIDATE_FD(shp, fd);
851 shp->fdstatus[fd] = mode;
852 return(fd);
861 register int fd = sh_open(name,O_RDONLY,0);
862 if(fd < 0)
864 return(fd);
895 int fd[2];
896 if(pipe(fd)<0 || (pv[0]=fd[0])<0 || (pv[1]=fd[1])<0)
912 int fd = accept(pv[0],(struct sockaddr*)0,(socklen_t*)0);
915 if(fd<0)
917 if((pv[out]=sh_fcntl(fd,F_DUPFD,10)) >=10)
918 sh_close(fd);
920 pv[out] = sh_iomovefd(fd);
988 int r, fd, close_exec;
992 fd = sffileno(sp);
993 VALIDATE_FD(shp, fd);
994 close_exec = shp->fdstatus[fd]&IOCLEX;
996 if(fd==0)
1021 if(fd==0 && !(was_share&SF_SHARE))
1040 endf.fd = fn;
1073 int fd;
1076 if((fd = sh_open(name,O_RDONLY,0)) > 0)
1078 if(fstat(fd,&statb) < 0)
1084 else if(fd < 0 && errno!=ENOENT)
1129 register int fd, iof;
1228 fd = io_heredoc(shp,iop,fname,traceon);
1230 sh_close(fd);
1237 if((fd=fname[0])>='0' && fd<='9')
1265 else if(fd=='-' && fname[1]==0)
1267 fd= -1;
1270 else if(fd=='p' && fname[1]==0)
1286 if((fd=sh_fcntl(dupfd,F_DUPFD,3))<0)
1288 VALIDATE_FD(shp, fd);
1290 shp->fdstatus[fd] = (shp->fdstatus[dupfd]&~IOCLEX);
1291 if(toclose<0 && shp->fdstatus[fd]&IOREAD)
1292 shp->fdstatus[fd] |= IODUP;
1316 fd=sh_chkopen(fname);
1361 if((fd=sh_open(tname?tname:fname,o_mode,RW_ALL)) <0)
1365 fchmod(fd,perm);
1471 if(fd==fn)
1473 if((r=sh_fcntl(fd,F_DUPFD,10)) > 0)
1475 fd = r;
1484 if(fd<0)
1495 return(fd);
1496 if(fd>=0)
1501 fn = fd;
1502 if(fd<10)
1504 if((fn=fcntl(fd,F_DUPFD,10)) < 0)
1508 shp->fdstatus[fn] = shp->fdstatus[fd];
1509 sh_close(fd);
1510 fd = fn;
1516 sh_iocheckfd(shp,fd);
1520 fd = sh_iorenumber(shp,sh_iomovefd(fd),fn);
1525 if(fd >2 && clexec)
1527 fcntl(fd,F_SETFD,FD_CLOEXEC);
1528 shp->fdstatus[fd] |= IOCLEX;
1546 register int fd;
1566 fd = (*cp=='$' || *cp=='\'')?' ':'\\';
1567 sfprintf(sfstderr," %c%s\n",fd,cp);
1587 fd = sffileno(outfile);
1592 lseek(fd,(off_t)0,SEEK_SET);
1593 shp->fdstatus[fd] = IOREAD;
1594 return(fd);
1674 if(origfd==job.fd)
1675 job.fd = savefd;
1697 register int fd, savefd, newfd;
1698 for(newfd=fd=0; fd < shp->topfd; fd++)
1700 if((savefd = filemap[fd].save_fd)< 0)
1701 filemap[newfd++] = filemap[fd];
1717 register int origfd, savefd, fd;
1720 for (fd = shp->topfd - 1; fd >= last; fd--)
1722 if(!flag && filemap[fd].subshell)
1726 if ((savefd = filemap[fd].save_fd) >= 0)
1734 origfd = filemap[fd].orig_fd;
1739 savefd = filemap[fd].save_fd;
1745 if(filemap[fd].tname == Empty && shp->exitval==0)
1747 else if(filemap[fd].tname)
1748 io_usename(filemap[fd].tname,(int*)0,shp->exitval?2:1);
1750 if ((savefd = filemap[fd].save_fd) >= 0)
1754 if(savefd==job.fd)
1755 job.fd=origfd;
1777 for (fd = last ; fd < shp->topfd; fd++)
1779 if(filemap[fd].subshell)
1780 filemap[last++] = filemap[fd];
1788 * returns access information on open file <fd>
1792 int sh_ioaccess(int fd,register int mode)
1798 if((flags=sh_iocheckfd(shp,fd))!=IOCLOSE)
1898 int fd = sffileno(iop);
1913 size = ed_read(shgd->ed_context, fd, (char*)buff, size,0);
2005 int sh_iocheckfd(Shell_t *shp, register int fd)
2009 VALIDATE_FD(shp, fd);
2011 if((n=shp->fdstatus[fd])&IOCLOSE)
2016 if((flags=fcntl(fd,F_GETFL,0)) < 0)
2017 return(shp->fdstatus[fd]=IOCLOSE);
2024 if((flags = fstat(fd,&statb))< 0)
2025 return(shp->fdstatus[fd]=IOCLOSE);
2027 if(read(fd,"",0) < 0)
2042 if(tty_check(fd))
2044 if(lseek(fd,NIL(off_t),SEEK_CUR)<0)
2048 if((fstat(fd,&statb)>=0) && S_ISSOCK(statb.st_mode))
2060 else if((fstat(fd,&statb)>=0) && (
2073 if(fd==0)
2075 else if(fd==1)
2077 shp->fdstatus[fd] = n;
2176 register int fd = sffileno(sp);
2202 if (fd < 0 || !VALIDATE_FD(shp, fd))
2207 if(sp==shp->heredocs && fd < 10 && flag==SF_NEW)
2209 fd = sfsetfd(sp,10);
2210 fcntl(fd,F_SETFD,FD_CLOEXEC);
2212 if(fd < 3)
2216 if(!shp->sftable[fd] && shp->fdstatus[fd]==IOCLOSE)
2218 shp->sftable[fd] = sp;
2222 shp->fdstatus[fd] = flag;
2223 sh_iostream(shp,fd);
2243 shp->sftable[fd] = 0;
2244 shp->fdstatus[fd]=IOCLOSE;
2466 ssize_t sh_read(register int fd, void* buff, size_t n)
2471 VALIDATE_FD(shp, fd);
2472 if(sp=shp->sftable[fd])
2475 return(read(fd,buff,n));
2482 ssize_t sh_write(register int fd, const void* buff, size_t n)
2487 VALIDATE_FD(shp, fd);
2488 if(sp=shp->sftable[fd])
2491 return(write(fd,buff,n));
2498 off_t sh_seek(register int fd, off_t offset, int whence)
2503 VALIDATE_FD(shp, fd);
2504 if((sp=shp->sftable[fd]) && (sfset(sp,0,0)&(SF_READ|SF_WRITE)))
2507 return(lseek(fd,offset,whence));
2514 register int fd = dup(old);
2517 VALIDATE_FD(shp, fd);
2518 if(fd>=0)
2522 shp->fdstatus[fd] = (shp->fdstatus[old]&~IOCLEX);
2524 (*fdnotify)(old,fd);
2526 return(fd);
2530 int sh_fcntl(register int fd, int op, ...)
2538 newfd = fcntl(fd,op,arg);
2540 VALIDATE_FD(shp, fd);
2546 if(shp->fdstatus[fd] == IOCLOSE)
2547 shp->fdstatus[fd] = 0;
2548 shp->fdstatus[newfd] = (shp->fdstatus[fd]&~IOCLEX);
2550 (*fdnotify)(fd,newfd);
2553 if(shp->fdstatus[fd] == IOCLOSE)
2554 shp->fdstatus[fd] = 0;
2556 shp->fdstatus[fd] |= IOCLEX;
2558 shp->fdstatus[fd] &= ~IOCLEX;
2572 * give file descriptor <fd> and <mode>, return an iostream pointer
2574 * <fd> must be a non-negative number ofr SH_IOCOPROCESS or SH_IOHISTFILE.
2578 Sfio_t *sh_iogetiop(int fd, int mode)
2588 switch(fd)
2593 fd = sffileno(shp->gd->hist_ptr->histfp);
2597 fd = shp->coutpipe;
2599 fd = shp->cpipe[0];
2602 if(fd<0 || !sh_iovalidfd(shp,fd))
2603 fd = -1;
2605 if(fd<0)
2610 if(!(n=shp->fdstatus[fd]))
2611 n = sh_iocheckfd(shp,fd);
2616 VALIDATE_FD(shp, fd);
2617 if(!(iop = shp->sftable[fd]))
2618 iop=sh_iostream(shp,fd);
2632 Sfio_t *sh_fd2sfio(int fd)
2638 VALIDATE_FD(shp, fd);
2639 sp = shp->sftable[fd];
2640 if(!sp && (status = sh_iocheckfd(shp,fd))!=IOCLOSE)
2647 sp = sfnew(NULL, NULL, -1, fd,flags);
2648 shp->sftable[fd] = sp;
2669 int sh_isdevfd(register const char *fd)
2671 if(!fd || memcmp(fd,"/dev/fd/",8) || fd[8]==0)
2673 for ( fd=&fd[8] ; *fd != '\0' ; fd++ )
2675 if (*fd < '0' || *fd > '9')