File: rfc2045_fromfd.c

package info (click to toggle)
swi-prolog 7.2.3%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,180 kB
  • ctags: 45,684
  • sloc: ansic: 330,358; perl: 268,104; sh: 6,795; java: 4,904; makefile: 4,561; cpp: 4,153; ruby: 1,594; yacc: 843; xml: 82; sed: 12; sql: 6
file content (46 lines) | stat: -rw-r--r-- 846 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
41
42
43
44
45
46
/*
** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
** distribution information.
*/

/*
** $Id$
*/
#if	HAVE_CONFIG_H
#include	"config.h"
#endif

#include	<sys/types.h>

#include	"rfc2045.h"
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#ifdef __WINDOWS__
#include <io.h>
#define read _read
#define lseek _lseek
#endif

/* Convert a message to the RFC2045 structure */

struct rfc2045 *rfc2045_fromfd(int fd)
{
struct	rfc2045	*rfc;
char	buf[BUFSIZ];
int	n;
off_t	orig_pos;

	if ((orig_pos=lseek(fd, 0L, SEEK_CUR)) == (off_t)-1) return (NULL);
	if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1)	return (NULL);
	if ((rfc=rfc2045_alloc()) == 0)	return (NULL);

	while ((n=read(fd, buf, sizeof(buf))) > 0)
		rfc2045_parse(rfc, buf, n);
	if (lseek(fd, orig_pos, SEEK_SET) == (off_t)-1)
	{
		rfc2045_free(rfc);
		rfc=0;
	}
	return (rfc);
}