#include #include #include #include #include #include #include #include #include #include #include #define FILENAME_TAG 1000000 int main(int argc, char ** argv) { char buf[300]; FD_t fd; Header h; int count, type; int end; char * name, * filename, * version, * release; if (argc != 2) { fprintf(stderr, "usage: dmphdlist \n"); exit(1); } strcpy(buf, argv[1]); strcat(buf, "/RedHat/base/hdlist"); fd = fdOpen(buf, O_RDONLY, 0644); if (fdFileno(fd) < 0) { fprintf(stderr,"error opening file %s: %s\n", buf, strerror(errno)); return 1; } end = fdLseek(fd, 0, SEEK_END); fdLseek(fd, 0, SEEK_SET); while (end > fdLseek(fd, 0, SEEK_CUR)) { h = headerRead(fd, HEADER_MAGIC_YES); if (!h) { fprintf(stderr, "error reading header at %d\n", (int) fdLseek(fd, 0, SEEK_CUR)); exit(1); } headerGetEntry(h, FILENAME_TAG, &type, (void *) &filename, &count); headerGetEntry(h, RPMTAG_NAME, &type, (void *) &name, &count); headerGetEntry(h, RPMTAG_VERSION, &type, (void *) &version, &count); headerGetEntry(h, RPMTAG_RELEASE, &type, (void *) &release, &count); printf("%-35s\t==\t%s %s %s\n", filename, name, version, release); headerFree(h); } fdClose(fd); return 0; }