# 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 "rpmlead.h"
    00016 #include "debug.h"
    00017
    00018 /* The lead needs to be 8 byte aligned */
    00019
    00020 int writeLead(FD_t fd, const struct rpmlead *lead)
    00021 {
    00022     struct rpmlead l;
    00023
    00024     memcpy(&l, lead, sizeof(*lead));
    00025
    00026     l.magic[0] = RPMLEAD_MAGIC0;
    00027     l.magic[1] = RPMLEAD_MAGIC1;
    00028     l.magic[2] = RPMLEAD_MAGIC2;
    00029     l.magic[3] = RPMLEAD_MAGIC3;
    00030
    00031     l.type = htons(l.type);
    00032     l.archnum = htons(l.archnum);
    00033     l.osnum = htons(l.osnum);
    00034     l.signature_type = htons(l.signature_type);
    00035
    00036     /*@-sizeoftype@*/
    00037     if (Fwrite(&l, sizeof(char), sizeof(l), fd) != sizeof(l)) {
    00038         return 1;
    00039     }
    00040     /*@=sizeoftype@*/
    00041
    00042     return 0;
    00043 }
    00044
    00045 int readLead(FD_t fd, struct rpmlead *lead)
    00046 {
    00047     memset(lead, 0, sizeof(*lead));
    00048     /*@-type@*/ /* FIX: remove timed read */
    00049     if (timedRead(fd, (char *)lead, sizeof(*lead)) != sizeof(*lead)) {
    00050         rpmError(RPMERR_READ, _("read failed: %s (%d)\n"), Fstrerror(fd),
    00051               errno);
    00052         return 1;
    00053     }
    00054     /*@=type@*/
    00055
    00056     lead->type = ntohs(lead->type);
    00057     lead->archnum = ntohs(lead->archnum);
    00058     lead->osnum = ntohs(lead->osnum);
    00059
    00060     if (lead->major >= 2)
    00061         lead->signature_type = ntohs(lead->signature_type);
    00062
    00063     return 0;
    00064 }