added more i18n strings
[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
20 /* The lead needs to be 8 byte aligned */
21
22 int writeLead(int fd, struct rpmlead *lead)
23 {
24     struct rpmlead l;
25
26     memcpy(&l, lead, sizeof(*lead));
27     
28     l.magic[0] = RPMLEAD_MAGIC0;
29     l.magic[1] = RPMLEAD_MAGIC1;
30     l.magic[2] = RPMLEAD_MAGIC2;
31     l.magic[3] = RPMLEAD_MAGIC3;
32
33     l.type = htons(l.type);
34     l.archnum = htons(l.archnum);
35     l.osnum = htons(l.osnum);
36     l.signature_type = htons(l.signature_type);
37         
38     if (write(fd, &l, sizeof(l)) < 0) {
39         return 1;
40     }
41
42     return 0;
43 }
44
45 int readLead(int fd, struct rpmlead *lead)
46 {
47     if (timedRead(fd, lead, sizeof(*lead)) != sizeof(*lead)) {
48         rpmError(RPMERR_READERROR, _("read failed: %s (%d)"), strerror(errno), 
49               errno);
50         return 1;
51     }
52
53     lead->type = ntohs(lead->type);
54     lead->archnum = ntohs(lead->archnum);
55     lead->osnum = ntohs(lead->osnum);
56
57     if (lead->major >= 2)
58         lead->signature_type = ntohs(lead->signature_type);
59
60     return 0;
61 }
62