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