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