2 * libdpkg - Debian packaging suite library routines
3 * dbdir.c - on-disk database directory functions
5 * Copyright © 2011 Guillem Jover <guillem@debian.org>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 #include <sys/types.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/fsys.h>
32 static const char *db_dir
= ADMINDIR
;
35 * Set current on-disk database directory.
37 * The directory is initially set to ADMINDIR, this function can be used to
38 * set the directory to a new value, or to set it to a default value if dir
39 * is NULL. For the latter the order is, value from environment variable
40 * DPKG_ADMINDIR, and then the built-in default ADMINDIR,
42 * @param dir The new database directory, or NULL to set to default.
44 * @return The new database directory.
47 dpkg_db_set_dir(const char *dir
)
52 env
= getenv("DPKG_ADMINDIR");
56 db_dir
= dpkg_fsys_get_path(ADMINDIR
);
65 * Get current on-disk database directory.
67 * @return The current database directory.
76 * Get a pathname to the current on-disk database directory.
78 * This function returns an allocated string, which should be freed with
81 * @param pathpart The pathpart to append to the new pathname.
83 * @return The newly allocated pathname.
86 dpkg_db_get_path(const char *pathpart
)
88 return str_fmt("%s/%s", db_dir
, pathpart
);