-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathliburead.c
36 lines (32 loc) · 880 Bytes
/
liburead.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* FUNET-NJE/HUJI-NJE Client utilities
*
* Common set of client used utility routines.
* These are collected to here from various modules for eased
* maintance.
*
* Matti Aarnio <[email protected]> 12-Feb-1991, 26-Sep-1993
*/
#include "prototypes.h"
#include "clientutils.h"
/* Uread() -- for a couple of external routines of HUJI-NJE */
int
Uread( buf,size,fd)
void *buf;
const int size;
FILE *fd;
{
short NewSize;
long filepos = ftell(fd);
if (fread(&NewSize, sizeof(NewSize), 1, fd) != 1)
return 0; /* Probably end of file */
NewSize = ntohs(NewSize);
if (NewSize > size) { /* Can't reduce size, so can't recover */
logger(1, "UREAD: have to read %d into a buffer of only %d, filepos=%d\n",
NewSize, size, filepos);
bug_check("Uread - buffer too small");
}
if (fread(buf, NewSize, 1, fd) == 1) {
return NewSize;
}
return 0;
}