fix blocking_read prototype

This commit is contained in:
tg 2010-08-28 16:47:11 +00:00
parent 4e08a79555
commit 297e2ced89
4 changed files with 28 additions and 27 deletions

4
edit.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.196 2010/07/25 11:35:40 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.197 2010/08/28 16:47:08 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -148,7 +148,7 @@ static int
x_getc(void)
{
char c;
int n;
ssize_t n;
while ((n = blocking_read(STDIN_FILENO, &c, 1)) < 0 && errno == EINTR)
if (trap) {

20
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.142 2010/08/28 15:48:19 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.143 2010/08/28 16:47:09 tg Exp $");
unsigned char chtypes[UCHAR_MAX + 1]; /* type bits for unsigned char */
@ -1021,19 +1021,20 @@ strip_nuls(char *buf, int nbytes)
}
}
/* Like read(2), but if read fails due to non-blocking flag, resets flag
* and restarts read.
/*
* Like read(2), but if read fails due to non-blocking flag,
* resets flag and restarts read.
*/
int
blocking_read(int fd, char *buf, int nbytes)
ssize_t
blocking_read(int fd, char *buf, size_t nbytes)
{
int ret;
int tried_reset = 0;
ssize_t ret;
bool tried_reset = false;
while ((ret = read(fd, buf, nbytes)) < 0) {
if (!tried_reset && errno == EAGAIN) {
if (reset_nonblock(fd) > 0) {
tried_reset = 1;
tried_reset = true;
continue;
}
errno = EAGAIN;
@ -1043,7 +1044,8 @@ blocking_read(int fd, char *buf, int nbytes)
return (ret);
}
/* Reset the non-blocking flag on the specified file descriptor.
/*
* Reset the non-blocking flag on the specified file descriptor.
* Returns -1 if there was an error, 0 if non-blocking wasn't set,
* 1 if it was.
*/

4
sh.h
View File

@ -150,7 +150,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.407 2010/08/28 15:48:20 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.408 2010/08/28 16:47:10 tg Exp $");
#endif
#define MKSH_VERSION "R39 2010/08/24"
@ -1611,7 +1611,7 @@ void print_columns(struct shf *, int,
char *(*)(char *, int, int, const void *),
const void *, int, int, bool);
void strip_nuls(char *, int);
int blocking_read(int, char *, int)
ssize_t blocking_read(int, char *, size_t)
MKSH_A_BOUNDED(buffer, 2, 3);
int reset_nonblock(int);
char *ksh_get_wd(size_t *);

27
shf.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.36 2010/07/19 22:41:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.37 2010/08/28 16:47:11 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -395,6 +395,8 @@ shf_emptybuf(struct shf *shf, int flags)
static int
shf_fillbuf(struct shf *shf)
{
ssize_t n;
if (shf->flags & SHF_STRING)
return (0);
@ -414,23 +416,20 @@ shf_fillbuf(struct shf *shf)
shf->rp = shf->buf;
while (1) {
shf->rnleft = blocking_read(shf->fd, (char *) shf->buf,
shf->rbsize);
if (shf->rnleft < 0 && errno == EINTR &&
!(shf->flags & SHF_INTERRUPT))
n = blocking_read(shf->fd, (char *)shf->buf, shf->rbsize);
if (n < 0 && errno == EINTR && !(shf->flags & SHF_INTERRUPT))
continue;
break;
}
if (shf->rnleft <= 0) {
if (shf->rnleft < 0) {
shf->flags |= SHF_ERROR;
shf->errno_ = errno;
shf->rnleft = 0;
shf->rp = shf->buf;
return (EOF);
}
shf->flags |= SHF_EOF;
if (n < 0) {
shf->flags |= SHF_ERROR;
shf->errno_ = errno;
shf->rnleft = 0;
shf->rp = shf->buf;
return (EOF);
}
if ((shf->rnleft = n) == 0)
shf->flags |= SHF_EOF;
return (0);
}