Move important information up in -Si output
[pacman-ng.git] / lib / libalpm / alpm.c
blobc58a406928c22b5b013717e9971c5fbe11b7fa66
1 /*
2 * alpm.c
4 * Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifdef HAVE_LIBCURL
25 #include <curl/curl.h>
26 #endif
28 /* libalpm */
29 #include "alpm.h"
30 #include "alpm_list.h"
31 #include "handle.h"
32 #include "log.h"
33 #include "util.h"
35 /** \addtogroup alpm_interface Interface Functions
36 * @brief Functions to initialize and release libalpm
37 * @{
40 /** Initializes the library. This must be called before any other
41 * functions are called.
42 * @param root the root path for all filesystem operations
43 * @param dbpath the absolute path to the libalpm database
44 * @param err an optional variable to hold any error return codes
45 * @return a context handle on success, NULL on error, err will be set if provided
47 alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
48 alpm_errno_t *err)
50 alpm_errno_t myerr;
51 const char *lf = "db.lck";
52 size_t lockfilelen;
53 alpm_handle_t *myhandle = _alpm_handle_new();
55 if(myhandle == NULL) {
56 myerr = ALPM_ERR_MEMORY;
57 goto cleanup;
59 if((myerr = _alpm_set_directory_option(root, &(myhandle->root), 1))) {
60 goto cleanup;
62 if((myerr = _alpm_set_directory_option(dbpath, &(myhandle->dbpath), 1))) {
63 goto cleanup;
66 lockfilelen = strlen(myhandle->dbpath) + strlen(lf) + 1;
67 myhandle->lockfile = calloc(lockfilelen, sizeof(char));
68 snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
70 if(_alpm_db_register_local(myhandle) == NULL) {
71 myerr = myhandle->pm_errno;
72 goto cleanup;
75 #ifdef ENABLE_NLS
76 bindtextdomain("libalpm", LOCALEDIR);
77 #endif
79 return myhandle;
81 cleanup:
82 _alpm_handle_free(myhandle);
83 if(err && myerr) {
84 *err = myerr;
86 return NULL;
89 /** Release the library. This should be the last alpm call you make.
90 * After this returns, handle should be considered invalid and cannot be reused
91 * in any way.
92 * @param myhandle the context handle
93 * @return 0 on success, -1 on error
95 int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
97 int ret = 0;
98 alpm_db_t *db;
100 CHECK_HANDLE(myhandle, return -1);
102 /* close local database */
103 db = myhandle->db_local;
104 if(db) {
105 db->ops->unregister(db);
106 myhandle->db_local = NULL;
109 if(alpm_unregister_all_syncdbs(myhandle) == -1) {
110 ret = -1;
113 _alpm_handle_unlock(myhandle);
114 _alpm_handle_free(myhandle);
116 #ifdef HAVE_LIBCURL
117 curl_global_cleanup();
118 #endif
120 return ret;
123 /** @} */
125 /** @defgroup alpm_misc Miscellaneous Functions
126 * @brief Various libalpm functions
129 /** Get the version of library.
130 * @return the library version, e.g. "6.0.4"
131 * */
132 const char SYMEXPORT *alpm_version(void)
134 return LIB_VERSION;
137 /** Get the capabilities of the library.
138 * @return a bitmask of the capabilities
139 * */
140 enum alpm_caps SYMEXPORT alpm_capabilities(void)
142 return 0
143 #ifdef ENABLE_NLS
144 | ALPM_CAPABILITY_NLS
145 #endif
146 #ifdef HAVE_LIBCURL
147 | ALPM_CAPABILITY_DOWNLOADER
148 #endif
149 #ifdef HAVE_LIBGPGME
150 | ALPM_CAPABILITY_SIGNATURES
151 #endif
152 | 0;
155 /* vim: set ts=2 sw=2 noet: */