1 /* Copyright (C) 1999-2002 Free Software Foundation, Inc.
3 This file is part of GNU Bash, the Bourne Again SHell.
5 Bash is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
10 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with Bash; see the file COPYING. If not, write to the Free Software
17 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21 #include <sys/types.h>
23 #if defined (HAVE_UNISTD_H)
37 /* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
38 error causes the loop to break. */
47 while ((r = read (fd, buf, len)) < 0 && errno == EINTR)
52 /* Read LEN bytes from FD into BUF. Retry the read on EINTR, up to three
53 interrupts. Any other error causes the loop to break. */
61 zreadintr (fd, buf, len)
71 r = read (fd, buf, len);
74 if (r == -1 && errno == EINTR)
76 if (++nintr > NUM_INTR)
84 /* Read one character from FD and return it in CP. Return values are as
85 in read(2). This does some local buffering to avoid many one-character
86 calls to read(2), like those the `read' builtin performs. */
88 static char lbuf[128];
89 static size_t lind, lused;
98 if (lind == lused || lused == 0)
100 nr = zread (fd, lbuf, sizeof (lbuf));
120 /* Sync the seek pointer for FD so that the kernel's idea of the last char
121 read is the last char returned by zreadc. */
132 r = lseek (fd, -off, SEEK_CUR);