po: Update German man pages translation
[dpkg.git] / lib / dpkg / dbdir.c
blobfecd4842fabfae2e5598709907f90a0dae33ea4d
1 /*
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/>.
21 #include <config.h>
22 #include <compat.h>
24 #include <sys/types.h>
26 #include <stdlib.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/fsys.h>
32 static const char *db_dir = ADMINDIR;
34 /**
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.
46 const char *
47 dpkg_db_set_dir(const char *dir)
49 if (dir == NULL) {
50 const char *env;
52 env = getenv("DPKG_ADMINDIR");
53 if (env)
54 db_dir = env;
55 else
56 db_dir = dpkg_fsys_get_path(ADMINDIR);
57 } else {
58 db_dir = dir;
61 return db_dir;
64 /**
65 * Get current on-disk database directory.
67 * @return The current database directory.
69 const char *
70 dpkg_db_get_dir(void)
72 return db_dir;
75 /**
76 * Get a pathname to the current on-disk database directory.
78 * This function returns an allocated string, which should be freed with
79 * free(2).
81 * @param pathpart The pathpart to append to the new pathname.
83 * @return The newly allocated pathname.
85 char *
86 dpkg_db_get_path(const char *pathpart)
88 return str_fmt("%s/%s", db_dir, pathpart);