]>
git.ipfire.org Git - thirdparty/bash.git/blob - lib/sh/zread.c
0d5320a18002bf8a47d615903adc7b62ae62c262
1 /* Copyright (C) 1999 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. */
70 r
= read (fd
, buf
, len
);
73 if (r
== -1 && errno
== EINTR
)
75 if (++nintr
> NUM_INTR
)
83 /* Read one character from FD and return it in CP. Return values are as
84 in read(2). This does some local buffering to avoid many one-character
85 calls to read(2), like those the `read' builtin performs. */
87 static unsigned char lbuf
[128];
88 static int lind
, lused
;
97 if (lind
== lused
|| lused
== 0)
99 lused
= zread (fd
, lbuf
, sizeof (lbuf
));
105 *cp
= (char)lbuf
[lind
++];
115 /* Sync the seek pointer for FD so that the kernel's idea of the last char
116 read is the last char returned by zreadc. */
125 lseek (fd
, -off
, SEEK_CUR
);