1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1997-11-18 11:13:56 +08:00
|
|
|
|
1997-11-18 22:25:55 +08:00
|
|
|
#if HAVE_MACHINE_TYPES_H
|
1996-09-26 03:16:05 +08:00
|
|
|
# include <machine/types.h>
|
|
|
|
#endif
|
|
|
|
|
1996-02-15 01:55:28 +08:00
|
|
|
#include <netinet/in.h>
|
1996-01-05 11:08:34 +08:00
|
|
|
|
1996-11-19 02:02:36 +08:00
|
|
|
#include "rpmlib.h"
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1996-01-05 11:05:34 +08:00
|
|
|
#include "rpmlead.h"
|
|
|
|
|
1996-06-20 02:18:04 +08:00
|
|
|
/* The lead needs to be 8 byte aligned */
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
int writeLead(FD_t fd, struct rpmlead *lead)
|
1996-01-05 11:05:34 +08:00
|
|
|
{
|
|
|
|
struct rpmlead l;
|
|
|
|
|
|
|
|
memcpy(&l, lead, sizeof(*lead));
|
|
|
|
|
|
|
|
l.magic[0] = RPMLEAD_MAGIC0;
|
|
|
|
l.magic[1] = RPMLEAD_MAGIC1;
|
|
|
|
l.magic[2] = RPMLEAD_MAGIC2;
|
|
|
|
l.magic[3] = RPMLEAD_MAGIC3;
|
|
|
|
|
|
|
|
l.type = htons(l.type);
|
|
|
|
l.archnum = htons(l.archnum);
|
|
|
|
l.osnum = htons(l.osnum);
|
|
|
|
l.signature_type = htons(l.signature_type);
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdWrite(fd, &l, sizeof(l)) < 0) {
|
1997-10-18 02:12:09 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1996-01-05 11:05:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
int readLead(FD_t fd, struct rpmlead *lead)
|
1996-01-05 11:05:34 +08:00
|
|
|
{
|
1996-10-15 11:15:30 +08:00
|
|
|
if (timedRead(fd, lead, sizeof(*lead)) != sizeof(*lead)) {
|
1998-01-10 03:10:54 +08:00
|
|
|
rpmError(RPMERR_READERROR, _("read failed: %s (%d)"), strerror(errno),
|
1996-02-15 01:55:28 +08:00
|
|
|
errno);
|
|
|
|
return 1;
|
|
|
|
}
|
1996-01-05 11:05:34 +08:00
|
|
|
|
|
|
|
lead->type = ntohs(lead->type);
|
|
|
|
lead->archnum = ntohs(lead->archnum);
|
|
|
|
lead->osnum = ntohs(lead->osnum);
|
1996-02-15 01:55:28 +08:00
|
|
|
|
|
|
|
if (lead->major >= 2)
|
|
|
|
lead->signature_type = ntohs(lead->signature_type);
|
1996-01-05 11:05:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|