Main Page Modules Data Structures File List Data Fields Globals Related Pages

# lib/rpmlead.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #if HAVE_MACHINE_TYPES_H
    00008 # include <machine/types.h>
    00009 #endif
    00010
    00011 #include <netinet/in.h>
    00012
    00013 #include <rpmlib.h>
    00014
    00015 #include "signature.h"
    00016 #include "rpmlead.h"
    00017 #include "debug.h"
    00018
    00019 /*@unchecked@*/ /*@observer@*/
    00020 static unsigned char lead_magic[] = {
    00021     RPMLEAD_MAGIC0, RPMLEAD_MAGIC1, RPMLEAD_MAGIC2, RPMLEAD_MAGIC3
    00022 };
    00023
    00024 /* The lead needs to be 8 byte aligned */
    00025
    00026 rpmRC writeLead(FD_t fd, const struct rpmlead *lead)
    00027 {
    00028     struct rpmlead l;
    00029
    00030 /*@-boundswrite@*/
    00031     memcpy(&l, lead, sizeof(l));
    00032
    00033     memcpy(&l.magic, lead_magic, sizeof(l.magic));
    00034 /*@=boundswrite@*/
    00035     l.type = htons(l.type);
    00036     l.archnum = htons(l.archnum);
    00037     l.osnum = htons(l.osnum);
    00038     l.signature_type = htons(l.signature_type);
    00039
    00040 /*@-boundswrite@*/
    00041     if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l))
    00042         return RPMRC_FAIL;
    00043 /*@=boundswrite@*/
    00044
    00045     return RPMRC_OK;
    00046 }
    00047
    00048 rpmRC readLead(FD_t fd, struct rpmlead *lead)
    00049 {
    00050 /*@-boundswrite@*/
    00051     memset(lead, 0, sizeof(*lead));
    00052 /*@=boundswrite@*/
    00053     /*@-type@*/ /* FIX: remove timed read */
    00054     if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
    00055         rpmError(RPMERR_READ, _("read failed: %s (%d)\n"), Fstrerror(fd),
    00056               errno);
    00057         return RPMRC_FAIL;
    00058     }
    00059     /*@=type@*/
    00060
    00061     if (memcmp(lead->magic, lead_magic, sizeof(lead_magic)))
    00062         return RPMRC_FAIL;
    00063     lead->type = ntohs(lead->type);
    00064     lead->archnum = ntohs(lead->archnum);
    00065     lead->osnum = ntohs(lead->osnum);
    00066     lead->signature_type = ntohs(lead->signature_type);
    00067     if (lead->signature_type != RPMSIGTYPE_HEADERSIG)
    00068         return RPMRC_FAIL;
    00069
    00070     return RPMRC_OK;
    00071 }