summaryrefslogtreecommitdiff
path: root/revdep.h
blob: c6beeb4842847002447ebff62b9c5c4aca9c6f27 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * revdep - reverse dependency checker for rawnix
 *
 * Copyright (c) 2025 zorz@gmx.com
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Concept based on revdep by James Buren for CRUX Linux.
 */

#ifndef REVDEP_H
#define REVDEP_H

#include <stddef.h>
#include <stdbool.h>

#define VERSION "1.3.0"

/* default paths */
#define PKG_DB_PATH    "/var/lib/pkg/db"
#define REVDEP_DIR     "/etc/revdep.d"

/*
 * System library path, as musl's dynamic linker has it: the file
 * /etc/ld-musl-x86_64.path if it exists, otherwise musl's built-in
 * default.
 */
#define MUSL_PATH_FILE "/etc/ld-musl-x86_64.path"
#define MUSL_SYS_PATH  "/lib:/usr/local/lib:/usr/lib"

/* verbosity levels */
enum {
	V_QUIET  = 0,   /* package names only           */
	V_NORMAL = 1,   /* formatted status per package  */
	V_FILES  = 2,   /* include broken files          */
	V_DETAIL = 3,   /* include missing library names */
	V_DEBUG  = 4    /* trace everything              */
};

/* dynamic string array */
typedef struct {
	char   **items;
	size_t   count;
	size_t   capacity;
} strvec_t;

/* package */
typedef struct {
	char     *name;
	char     *version;
	strvec_t  files;
	strvec_t  dirs;    /* extra lib search dirs from /etc/revdep.d */
	bool      ignore;
} pkg_t;

/* package array */
typedef struct {
	pkg_t  **items;
	size_t   count;
	size_t   capacity;
} pkgvec_t;

/* ELF info */
typedef struct {
	char     *path;
	strvec_t  needed;
	strvec_t  rpath;
	strvec_t  runpath;
	bool      valid;
} elfinfo_t;

/* --- strvec --------------------------------------------------------- */
void     strvec_init(strvec_t *v);
void     strvec_free(strvec_t *v);
bool     strvec_push(strvec_t *v, const char *s);
bool     strvec_contains(const strvec_t *v, const char *s);

/* --- pkg ------------------------------------------------------------- */
pkg_t   *pkg_new(const char *name, const char *version);
void     pkg_free(pkg_t *p);

/* --- pkgvec ---------------------------------------------------------- */
void     pkgvec_init(pkgvec_t *v);
void     pkgvec_free(pkgvec_t *v);
bool     pkgvec_push(pkgvec_t *v, pkg_t *p);
pkg_t   *pkgvec_find(const pkgvec_t *v, const char *name);

/* --- pkg database ---------------------------------------------------- */
bool     db_read(const char *path, pkgvec_t *pkgs);
bool     db_read_dirs(const char *path, pkgvec_t *pkgs);

/* --- elf ------------------------------------------------------------- */
elfinfo_t *elf_inspect(const char *path);
void       elf_free(elfinfo_t *e);

/* --- elf cache ------------------------------------------------------- */
elfinfo_t *cache_lookup(const char *path);
void       cache_clear(void);

/* --- library resolution ---------------------------------------------- */
bool     lib_find(const elfinfo_t *elf, const pkg_t *pkg,
                  const char *lib, const strvec_t *sys_dirs);

/* --- python path checker --------------------------------------------- */
char    *py_installed_version(const pkgvec_t *pkgs);
bool     py_check_package(const pkg_t *pkg, const char *installed);

/* --- perl path checker ---------------------------------------------- */
char    *perl_installed_version(const pkgvec_t *pkgs);
bool     perl_check_package(const pkg_t *pkg, const char *installed);

/* --- package versions ----------------------------------------------- */
char    *pkg_upstream_version(const char *dbversion);

/* --- utility --------------------------------------------------------- */
char    *xstrdup(const char *s);
char    *xpathjoin(const char *dir, const char *file);
bool     is_regfile(const char *path);
char    *realpath_safe(const char *path);
void     strsplit(const char *s, char delim, strvec_t *v);

/* --- logging --------------------------------------------------------- */
extern int verbosity;
void     msg(int level, const char *fmt, ...);

#endif