-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrawget.c
40 lines (30 loc) · 914 Bytes
/
rawget.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
37
38
39
#include <stdio.h>
#include <stdlib.h>
int RAWGET_get( unsigned char *buffer, int max, FILE *f )
{
unsigned char c; // read buffer
int count = 0; // How many bytes read
// Special situation here, if we have a return from MIME_headers which indicates
// that we have data in a MIMEH_pushback, then we need to process that first, before we
// go back into the data file.
//
// Whilst we've got less bytes than the maximum availabe
// for the buffer, we keep on reading
//
while (count < max)
{
// If we do infact read in 1 bytes...
if (fread(&c,1,1,f)==1)
{
*buffer = c; // Set the byte in the buffer
buffer++; // move the buffer pointer
count++; // Increment the byte cound
if (c == '\n') // If we encounter a \n (or \r)
{
break; // Hop out of while loop
}
}
else break; // if we didn't read right, then jump out as well
}
return count;
}