/*1* $NetBSD: pread.c,v 1.2 1997/03/22 01:48:38 thorpej Exp $2*/34/*-5* Copyright (c) 19966* Matthias Drochner. All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16* 3. All advertising materials mentioning features or use of this software17* must display the following acknowledgement:18* This product includes software developed for the NetBSD Project19* by Matthias Drochner.20* 4. The name of the author may not be used to endorse or promote products21* derived from this software without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR24* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES25* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.26* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,27* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT28* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,29* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY30* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT31* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF32* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435/* read into destination in flat addr space */3637#include <stand.h>3839#include "libi386.h"4041#ifdef SAVE_MEMORY42#define BUFSIZE (1*1024)43#else44#define BUFSIZE (4*1024)45#endif4647static char buf[BUFSIZE];4849int50pread(fd, dest, size)51int fd;52vm_offset_t dest;53int size;54{55int rsize;5657rsize = size;58while (rsize > 0) {59int count, got;6061count = (rsize < BUFSIZE ? rsize : BUFSIZE);6263got = read(fd, buf, count);64if (got < 0)65return (-1);6667/* put to physical space */68vpbcopy(buf, dest, got);6970dest += got;71rsize -= got;72if (got < count)73break; /* EOF */74}75return (size - rsize);76}777879