File: query.c

package info (click to toggle)
cruft-ng 0.9.78
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,904 kB
  • sloc: cpp: 1,748; sh: 816; python: 262; makefile: 97; ansic: 82; perl: 75
file content (37 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (2)
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
#define LIBDPKG_VOLATILE_API

// gcc query.c $(pkgconf --static --libs libdpkg) -o query

#include <stdio.h>

#include <dpkg/dpkg.h>
#include <dpkg/db-fsys.h>
#include <dpkg/pkg-list.h>

int main(int argc, const char *const *argv)
{
    if(argc != 2) {
        fputs("usage: query path\n", stderr);
        return 1;
    }

    dpkg_program_init("query");
    modstatdb_open(msdbrw_readonly);
    ensure_allinstfiles_available_quiet();
    ensure_diversions();

    struct fsys_namenode *namenode;
    namenode = fsys_hash_find_node(argv[1], 0);

    if (namenode->divert) {
        fputs(namenode->divert->pkgset->name, stdout);
        fputs("\n", stdout);
    } else if(namenode->packages) {
        fputs(namenode->packages->pkg->set->name, stdout);
        fputs("\n", stdout);
    }

    modstatdb_shutdown();
    dpkg_program_done();
    return 0;
}