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

Generated at Mon Sep 24 10:37:20 2001 for rpm by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001