3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering/***********************************************************************
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* This software is part of the ast package *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* Copyright (c) 1982-2012 AT&T Intellectual Property *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* and is licensed under the *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* Eclipse Public License, Version 1.0 *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* by AT&T Intellectual Property *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* A copy of the License is available at *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* http://www.eclipse.org/org/documents/epl-v10.html *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* Information and Software Systems Research *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* AT&T Research *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* Florham Park NJ *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering* David Korn <dgk@research.att.com> *
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering***********************************************************************/
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering * Input/output file processing
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering# endif /* EAGAIN */
3b3154df7e2773332bb814e167187367a0ccae4aLennart Poettering# endif /* !O_NONBLOCK */
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering#endif /* FNDELAY */
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET)
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering#define RW_ALL (S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH)
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek#if defined(_lib_socket) && defined(_sys_socket) && defined(_hdr_netinet_in)
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering# define pipe(v) ((socketpair(AF_UNIX,SOCK_STREAM,0,v)<0||shutdown((v)[1],SHUT_RD)<0||fchmod((v)[1],S_IWUSR)<0||shutdown((v)[0],SHUT_WR)<0||fchmod((v)[0],S_IRUSR)<0)?(-1):0)
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering# define pipe(v) ((socketpair(AF_UNIX,SOCK_STREAM,0,v)<0||shutdown((v)[1],SHUT_RD)<0||shutdown((v)[0],SHUT_WR)<0)?(-1):0)
getaddrinfo(const char* node, const char* service, const struct addrinfo* hint, struct addrinfo **addr)
return EAI_SYSTEM;
if (hint)
case SOCK_STREAM:
#ifdef IPPROTO_SCTP
case IPPROTO_SCTP:
case SOCK_DGRAM:
if (!protocol)
if (!ip_port)
return EAI_SYSTEM;
return EAI_SYSTEM;
if (hint)
if (ap)
struct addrinfo* p;
switch (path[0])
#ifdef IPPROTO_SCTP
free(s);
if (fd)
errno = 0;
if (!p->ai_protocol)
if (!p->ai_socktype)
if (server && !bind(fd, p->ai_addr, p->ai_addrlen) && !listen(fd, 5) || !server && !connect(fd, p->ai_addr, p->ai_addrlen))
goto done;
goto done;
done:
if (fd >= 0)
return fd;
if(cur<0)
if(fd<0)
if(n > max)
n = max;
if(max)
if(max)
if(max)
if(sftable)
switch (errno)
case EINTR:
case EPIPE:
#ifdef ECONNRESET
case ECONNRESET:
#ifdef ESHUTDOWN
case ESHUTDOWN:
if(!active)
active = 0;
switch(fd)
return(sfstdin);
return(sfstdout);
return(sfstderr);
return(iop);
if(sp)
if(fd<0)
sp = 0;
else if(f2==0)
if(sp)
else if(sp)
return(f2);
if(fd<0)
if(fdnotify)
#ifdef O_SERVICE
errno = 0;
if(path==0)
if(*path==0)
fd = 0;
#ifdef O_SERVICE
if (fd < 0)
return(fd>=0);
if (fd >= 0)
goto ok;
if (fd >= 0)
if(nfd>=0)
goto ok;
#if SHOPT_REGRESS
ok:
return(fd);
if(fd < 0)
return(fd);
return(fdold);
return(fdnew);
#ifndef pipe
#if SHOPT_COSHELL
if(fd<0)
size_t n,m;
if(fd==0)
if(!close_exec)
if(mp)
if(pp)
if(sp)
if(mp)
if(pp)
if(mode==0)
stakputc(0);
stakseek(0);
switch(mode)
return(tname);
if(iop)
sh_subfork();
errno=0;
np = 0;
#if SHOPT_COSHELL
goto traceit;
if(traceon)
fname = 0;
number++;
goto fail;
goto traceit;
if(flag)
goto fail;
goto traceit;
goto fail;
else if(toclose>=0)
if(flag==0)
goto openit;
goto traceit;
#if SHOPT_FS_3D
if(perm>0)
#if _lib_fchmod
if(np)
return(indx);
if(np)
if(r==IOCLOSE)
goto fail;
if(r&IONOSEEK)
goto fail;
goto fail;
if(sp)
if(off<0)
extern const char e_notimp[];
if(!(r&IOREAD))
goto fail;
if(!(rp = regcache(fname, REG_SHELL|REG_NOSUB|REG_NEWLINE|REG_AUGMENTED|REG_FIRST|REG_LEFT|REG_RIGHT, &r)))
goto fail;
if(!sp)
goto fail;
return(fn);
if(!np)
if(flag==0 || tname || (flag==1 && fn==1 && (shp->fdstatus[fn]&IONOSEEK) && shp->outpipepid && shp->outpipepid==getpid()))
fd = r;
if(fd<0)
return(fd);
if(fd>=0)
if(np)
int32_t v;
goto fail;
goto fail;
v = fn;
goto fail;
return(indx);
fail:
if(traceon)
if(fno>=0)
if(traceon)
if(fno>=0)
if(infile)
return(fd);
#if SHOPT_DEVFD
if(origfd <0)
if(savefd >=0)
if(origfd<0)
if(origfd==0)
if(!flag)
#ifndef FNDELAY
# ifdef O_NDELAY
n &= ~O_NDELAY;
#ifdef O_NONBLOCK
n &= ~O_NONBLOCK;
errno = 0;
timeout = 0;
job_lock();
job_unlock();
if(sh_isstate(SH_INTERACTIVE) && sffileno(iop)==0 && io_prompt(shp,iop,shp->nextprompt)<0 && errno==EIO)
return(size);
int (*readf)(void*, int, char*, int, int);
#if SHOPT_HISTEXPAND
# if SHOPT_ESH
# if SHOPT_VSH
# if SHOPT_RAWONLY
timeout = (void*)sh_timeradd(sh_isstate(SH_GRACE)?1000L*TGRACE:1000L*shp->timeout,0,time_grace,shp);
if(timeout)
timeout=0;
#if SHOPT_HISTEXPAND
if(xp)
xp = 0;
return(rsize);
#ifdef F_GETFL
n |= IOREAD;
n |= IOWRITE;
n &= ~IOREAD;
n |= IOTTY;
n |= IONOSEEK;
#ifdef S_ISSOCK
n &= ~IOREAD;
n &= ~IOWRITE;
#ifdef S_ISSOCK
(statb.st_ino==0 && (statb.st_mode & ~(S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH|S_IXUSR|S_IXGRP|S_IXOTH|S_ISUID|S_ISGID))==0) ||
n |= IONOSEEK;
n |= IOSEEK;
if(fd==0)
n &= ~IOWRITE;
n &= ~IOREAD;
flag = 0;
flag = 0;
if(flag==0)
switch(flag)
if(c==HIST_CHAR)
c = *++cp;
if(c!= HIST_CHAR)
goto done;
goto done;
goto done;
if(cp)
done:
*endprompt = 0;
if(newfd<0)
if(fdnotify)
#ifdef DEBUG
if(fdnotify)
return(iop);
return(sp);
ssize_t n;
if(size>0)
#ifdef SF_ATEXIT
ndigits++;
goto skip;
if(i < wsize)
skip:
for(i=0;i<nrow;i++)
j += nrow;
if(j >= argn)
if(fd>=0)
if(fdnotify)
return(fd);
case F_DUPFD:
if(fdnotify)
case F_SETFD:
return(newfd);
return(umask(m));
return(iop);
switch(fd)
case SH_IOHISTFILE:
return(iop);
case SH_IOCOPROCESS:
if(fd<0)
return(iop);
return(iop);
return(iop);
return(iop);
return(old);
return(sp);
#ifdef PATH_BFPATH