BRL-CAD
mread.c
Go to the documentation of this file.
1 /* M R E A D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1992-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #ifdef HAVE_SYS_TYPES_H
24 # include <sys/types.h>
25 #endif
26 #include "bio.h"
27 
28 #include "bu/log.h"
29 
30 long int
31 bu_mread(int fd, void *bufp, long int n)
32 {
33  register long int count = 0;
34  register long int nread;
35  char *cbufp = (char *)bufp;
36 
37  while (count < n) {
38  nread = read(fd, cbufp, (size_t)(n-count));
39  if (UNLIKELY(nread < 0)) {
40  return nread;
41  }
42  if (UNLIKELY(nread == 0)) {
43  return count;
44  }
45  count += nread;
46  cbufp += nread;
47  }
48  return count;
49 }
50 
51 /*
52  * Local Variables:
53  * tab-width: 8
54  * mode: C
55  * indent-tabs-mode: t
56  * c-file-style: "stroustrup"
57  * End:
58  * ex: shiftwidth=4 tabstop=8
59  */
Header file for the BRL-CAD common definitions.
long int bu_mread(int fd, void *bufp, long int n)
Definition: mread.c:31
#define UNLIKELY(expression)
Definition: common.h:282