void do_accept(TARG, nstab, gstab) STR *TARG; STAB *nstab; STAB *gstab; { register STIO *nstio; register STIO *gstio; int len = sizeof buf; int fd; if (!nstab) goto badexit; if (!gstab) goto nuts; gstio = stab_io(gstab); nstio = stab_io(nstab); if (!gstio || !gstio->ifp) goto nuts; if (!nstio) nstio = stab_io(nstab) = stio_new(); else if (nstio->ifp) do_close(nstab,FALSE); fd = accept(fileno(gstio->ifp),(struct sockaddr *)buf,&len); if (fd < 0) goto badexit; nstio->ifp = fdopen(fd, "r"); nstio->ofp = fdopen(fd, "w"); nstio->type = 's'; if (!nstio->ifp || !nstio->ofp) { if (nstio->ifp) fclose(nstio->ifp); if (nstio->ofp) fclose(nstio->ofp); if (!nstio->ifp && !nstio->ofp) close(fd); goto badexit; } str_nset(TARG, buf, len); return; nuts: if (dowarn) warn("accept() on closed fd"); errno = EBADF; badexit: str_sset(TARG,&str_undef); return; }