aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sh/zread.c
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2014-02-26 09:36:43 -0500
committerChet Ramey <chet.ramey@case.edu>2014-02-26 09:36:43 -0500
commitac50fbac377e32b98d2de396f016ea81e8ee9961 (patch)
treef71882366b98fedf1a88a063103219a4935de926 /lib/sh/zread.c
parent4539d736f1aff232857a854fd2a68df0c98d9f34 (diff)
downloadandroid_external_bash-ac50fbac377e32b98d2de396f016ea81e8ee9961.tar.gz
android_external_bash-ac50fbac377e32b98d2de396f016ea81e8ee9961.tar.bz2
android_external_bash-ac50fbac377e32b98d2de396f016ea81e8ee9961.zip
Bash-4.3 distribution sources and documentation
Diffstat (limited to 'lib/sh/zread.c')
-rw-r--r--lib/sh/zread.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/lib/sh/zread.c b/lib/sh/zread.c
index 5db21a9..868f970 100644
--- a/lib/sh/zread.c
+++ b/lib/sh/zread.c
@@ -26,6 +26,7 @@
# include <unistd.h>
#endif
+#include <signal.h>
#include <errno.h>
#if !defined (errno)
@@ -36,6 +37,9 @@ extern int errno;
# define SEEK_CUR 1
#endif
+extern void check_signals_and_traps (void);
+extern int signal_is_trapped (int);
+
/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
error causes the loop to break. */
ssize_t
@@ -46,8 +50,22 @@ zread (fd, buf, len)
{
ssize_t r;
+#if 0
+#if defined (HAVE_SIGINTERRUPT)
+ if (signal_is_trapped (SIGCHLD))
+ siginterrupt (SIGCHLD, 1);
+#endif
+#endif
+
while ((r = read (fd, buf, len)) < 0 && errno == EINTR)
- ;
+ check_signals_and_traps (); /* XXX - should it be check_signals()? */
+
+#if 0
+#if defined (HAVE_SIGINTERRUPT)
+ siginterrupt (SIGCHLD, 0);
+#endif
+#endif
+
return r;
}
@@ -148,6 +166,34 @@ zreadcintr (fd, cp)
return 1;
}
+/* Like zreadc, but read a specified number of characters at a time. Used
+ for `read -N'. */
+ssize_t
+zreadn (fd, cp, len)
+ int fd;
+ char *cp;
+ size_t len;
+{
+ ssize_t nr;
+
+ if (lind == lused || lused == 0)
+ {
+ if (len > sizeof (lbuf))
+ len = sizeof (lbuf);
+ nr = zread (fd, lbuf, len);
+ lind = 0;
+ if (nr <= 0)
+ {
+ lused = 0;
+ return nr;
+ }
+ lused = nr;
+ }
+ if (cp)
+ *cp = lbuf[lind++];
+ return 1;
+}
+
void
zreset ()
{