2000-08-28 03:27:03 +08:00
|
|
|
/** \ingroup lead
|
|
|
|
* \file lib/rpmlead.c
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
1999-09-13 04:43:23 +08:00
|
|
|
#ifdef __LCLINT__
|
|
|
|
#define ntohl(_x) (_x)
|
|
|
|
#define ntohs(_x) (_x)
|
|
|
|
#define htonl(_x) (_x)
|
|
|
|
#define htons(_x) (_x)
|
|
|
|
#else
|
1996-02-15 01:55:28 +08:00
|
|
|
#include <netinet/in.h>
|
1999-09-13 04:43:23 +08:00
|
|
|
#endif /* __LCLINT__ */
|
1996-01-05 11:08:34 +08:00
|
|
|
|
1999-07-14 05:37:57 +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);
|
|
|
|
|
1999-11-11 06:09:49 +08:00
|
|
|
if (Fwrite(&l, sizeof(char), sizeof(l), fd) < 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
|
|
|
{
|
1999-11-05 05:26:08 +08:00
|
|
|
if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
|
2000-09-02 05:15:40 +08:00
|
|
|
rpmError(RPMERR_READ, _("read failed: %s (%d)"), Fstrerror(fd),
|
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;
|
|
|
|
}
|