summaryrefslogtreecommitdiff
path: root/lib/sh/zread.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh/zread.c')
-rw-r--r--lib/sh/zread.c65
1 files changed, 51 insertions, 14 deletions
diff --git a/lib/sh/zread.c b/lib/sh/zread.c
index 460234b..0fd1199 100644
--- a/lib/sh/zread.c
+++ b/lib/sh/zread.c
@@ -1,20 +1,22 @@
+/* zread - read data from file descriptor into buffer with retries */
+
/* Copyright (C) 1999-2002 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
- Bash is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
+ Bash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Bash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- Bash is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
-
- You should have received a copy of the GNU General Public License along
- with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <config.h>
@@ -58,7 +60,7 @@ zread (fd, buf, len)
#define NUM_INTR 3
ssize_t
-zreadintr (fd, buf, len)
+zreadretry (fd, buf, len)
int fd;
char *buf;
size_t len;
@@ -73,7 +75,7 @@ zreadintr (fd, buf, len)
return r;
if (r == -1 && errno == EINTR)
{
- if (++nintr > NUM_INTR)
+ if (++nintr >= NUM_INTR)
return -1;
continue;
}
@@ -81,6 +83,16 @@ zreadintr (fd, buf, len)
}
}
+/* Call read(2) and allow it to be interrupted. Just a stub for now. */
+ssize_t
+zreadintr (fd, buf, len)
+ int fd;
+ char *buf;
+ size_t len;
+{
+ return (read (fd, buf, len));
+}
+
/* Read one character from FD and return it in CP. Return values are as
in read(2). This does some local buffering to avoid many one-character
calls to read(2), like those the `read' builtin performs. */
@@ -111,6 +123,31 @@ zreadc (fd, cp)
return 1;
}
+/* Don't mix calls to zreadc and zreadcintr in the same function, since they
+ use the same local buffer. */
+ssize_t
+zreadcintr (fd, cp)
+ int fd;
+ char *cp;
+{
+ ssize_t nr;
+
+ if (lind == lused || lused == 0)
+ {
+ nr = zreadintr (fd, lbuf, sizeof (lbuf));
+ lind = 0;
+ if (nr <= 0)
+ {
+ lused = 0;
+ return nr;
+ }
+ lused = nr;
+ }
+ if (cp)
+ *cp = lbuf[lind++];
+ return 1;
+}
+
void
zreset ()
{