7 #if HAVE_MACHINE_TYPES_H
8 # include <machine/types.h>
11 #include <netinet/in.h>
15 #include "signature.h"
19 static unsigned char lead_magic[] = {
20 RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
23 /* The lead needs to be 8 byte aligned */
25 rpmRC writeLead(FD_t fd, const struct rpmlead *lead)
29 memcpy(&l, lead, sizeof(l));
31 memcpy(&l.magic, lead_magic, sizeof(l.magic));
32 l.type = htons(l.type);
33 l.archnum = htons(l.archnum);
34 l.osnum = htons(l.osnum);
35 l.signature_type = htons(l.signature_type);
37 if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
43 rpmRC readLead(FD_t fd, struct rpmlead *lead)
45 memset(lead, 0, sizeof(*lead));
46 /* FIX: remove timed read */
47 if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
49 rpmError(RPMERR_READ, _("read failed: %s (%d)\n"),
50 Fstrerror(fd), errno);
53 return RPMRC_NOTFOUND;
56 if (memcmp(lead->magic, lead_magic, sizeof(lead_magic)))
57 return RPMRC_NOTFOUND;
58 lead->type = ntohs(lead->type);
59 lead->archnum = ntohs(lead->archnum);
60 lead->osnum = ntohs(lead->osnum);
61 lead->signature_type = ntohs(lead->signature_type);
62 if (lead->signature_type != RPMSIGTYPE_HEADERSIG)
63 return RPMRC_NOTFOUND;