File: rawget.c

package info (click to toggle)
p3scan 2%3A2.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,568 kB
  • ctags: 2,371
  • sloc: ansic: 12,072; makefile: 253; sh: 234
file content (40 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (8)
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
40
#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;
}