home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / install / dmphdlist.c < prev    next >
C/C++ Source or Header  |  1997-09-17  |  1KB  |  62 lines

  1. #include <alloca.h>
  2. #include <ctype.h>
  3. #include <dirent.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <rpmlib.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12.  
  13. #define FILENAME_TAG 1000000
  14.  
  15. int main(int argc, char ** argv) {
  16.     char buf[300];
  17.     int fd;
  18.     Header h;
  19.     int count, type;
  20.     int end;
  21.     char * name, * filename, * version, * release;
  22.  
  23.     if (argc != 2) {
  24.     fprintf(stderr, "usage: dmphdlist <dir>\n");
  25.     exit(1);
  26.     }
  27.  
  28.     strcpy(buf, argv[1]);
  29.     strcat(buf, "/RedHat/base/hdlist");
  30.     
  31.     fd = open(buf, O_RDONLY, 0644);
  32.     if (fd < 0) {
  33.     fprintf(stderr,"error opening file %s: %s\n", buf, strerror(errno));
  34.     return 1;
  35.     }
  36.  
  37.     end = lseek(fd, 0, SEEK_END);
  38.     lseek(fd, 0, SEEK_SET);
  39.  
  40.     while (end > lseek(fd, 0, SEEK_CUR)) {
  41.     h = headerRead(fd, HEADER_MAGIC_YES);
  42.     if (!h) {
  43.         fprintf(stderr, "error reading header at %d\n", 
  44.             (int) lseek(fd, 0, SEEK_CUR));
  45.         exit(1);
  46.     }
  47.  
  48.     headerGetEntry(h, FILENAME_TAG, &type, (void *) &filename, &count);
  49.     headerGetEntry(h, RPMTAG_NAME, &type, (void *) &name, &count);
  50.     headerGetEntry(h, RPMTAG_VERSION, &type, (void *) &version, &count);
  51.     headerGetEntry(h, RPMTAG_RELEASE, &type, (void *) &release, &count);
  52.  
  53.     printf("%-35s\t==\t%s %s %s\n", filename, name, version, release);
  54.  
  55.     headerFree(h);
  56.     }
  57.  
  58.     close(fd);
  59.  
  60.     return 0;
  61. }
  62.