1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* Example 3 from Maximum RPM book by Edward C. Bailey
* Updated for 2.5.6 20 Mar 99 by Scott Bronson
* Updated again for 3.0.3 4 Oct 99 by Scott Bronson
*/
/* This uses rpmlib to search the database for the RPM
* named on the command line.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <rpmlib.h>
#ifndef HEADER_DUMP_INLINE
/**
* Dump a header in human readable format (for debugging).
* @param h header
* @param flags 0 or HEADER_DUMP_INLINE
* @param tags array of tag name/value pairs
*/
void headerDump(Header h, FILE *f, int flags,
const struct headerTagTableEntry_s * tags)
/*@globals fileSystem @*/
/*@modifies f, fileSystem @*/;
#define HEADER_DUMP_INLINE 1
#endif
int main( int argc, char **argv )
{
rpmdbMatchIterator mi;
Header h;
rpmdb db;
if( argc != 2 ) {
fprintf( stderr, "usage: showdb2 <search term>\n" );
exit(EXIT_FAILURE);
}
rpmReadConfigFiles( NULL, NULL );
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
fprintf( stderr, "cannot open RPM database.\n" );
exit( 1 );
}
mi = rpmdbInitIterator(db, RPMTAG_BASENAMES, argv[1], 0);
while ((h = rpmdbNextIterator(mi)) != NULL) {
headerDump( h, stdout, HEADER_DUMP_INLINE, rpmTagTable );
/*
* Note that the header reference is "owned" by the iterator,
* so no headerFree() is necessary.
*/
}
mi = rpmdbFreeIterator(mi);
rpmdbClose( db );
return 0;
}
|