fixed silly include file ordering problems on FreeBSD
[platform/upstream/rpm.git] / lib / rpmlead.c
1 #ifdef HAVE_MACHINE_TYPES_H
2 # include <machine/types.h>
3 #endif
4
5 #include <sys/types.h>
6 #include <netinet/in.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12
13 #include "rpmlib.h"
14 #include "rpmlead.h"
15 #include "tread.h"
16
17 /* The lead needs to be 8 byte aligned */
18
19 int writeLead(int fd, struct rpmlead *lead)
20 {
21     struct rpmlead l;
22
23     memcpy(&l, lead, sizeof(*lead));
24     
25     l.magic[0] = RPMLEAD_MAGIC0;
26     l.magic[1] = RPMLEAD_MAGIC1;
27     l.magic[2] = RPMLEAD_MAGIC2;
28     l.magic[3] = RPMLEAD_MAGIC3;
29
30     l.type = htons(l.type);
31     l.archnum = htons(l.archnum);
32     l.osnum = htons(l.osnum);
33     l.signature_type = htons(l.signature_type);
34         
35     write(fd, &l, sizeof(l));
36
37     return 0;
38 }
39
40 int readLead(int fd, struct rpmlead *lead)
41 {
42     if (timedRead(fd, lead, sizeof(*lead)) != sizeof(*lead)) {
43         rpmError(RPMERR_READERROR, "read failed: %s (%d)", strerror(errno), 
44               errno);
45         return 1;
46     }
47
48     lead->type = ntohs(lead->type);
49     lead->archnum = ntohs(lead->archnum);
50     lead->osnum = ntohs(lead->osnum);
51
52     if (lead->major >= 2)
53         lead->signature_type = ntohs(lead->signature_type);
54
55     return 0;
56 }
57