X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Futils.c;h=fb2c6aa20b05af1cfb9be9c27b3d8f3520c87a55;hb=d524a1339c6016f60dcebdddc7536f510a558ada;hp=8c7045298b7bf0546022fc25a8a705549df12659;hpb=f53a48eb9d74db3c71938e114b7f489c339bc003;p=ppp.git diff --git a/pppd/utils.c b/pppd/utils.c index 8c70452..fb2c6aa 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -33,7 +33,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: utils.c,v 1.20 2002/12/04 23:03:33 paulus Exp $" +#define RCSID "$Id: utils.c,v 1.21 2003/03/30 08:26:56 paulus Exp $" #include #include @@ -832,6 +832,32 @@ dump_packet(const char *tag, unsigned char *p, int len) dbglog("%s %P", tag, p, len); } +/* + * complete_read - read a full `count' bytes from fd, + * unless end-of-file or an error other than EINTR is encountered. + */ +ssize_t +complete_read(int fd, void *buf, size_t count) +{ + size_t done; + ssize_t nb; + char *ptr = buf; + + for (done = 0; done < count; ) { + nb = read(fd, ptr, count - done); + if (nb < 0) { + if (errno == EINTR) + continue; + return -1; + } + if (nb == 0) + break; + done += nb; + ptr += nb; + } + return done; +} + /* Procedures for locking the serial device using a lock file. */ #ifndef LOCK_DIR #ifdef __linux__