libalpm
Arch Linux Package Manager Library
util.h File Reference
#include "alpm_list.h"
#include "alpm.h"
#include "package.h"
#include "handle.h"
#include "util-common.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <sys/types.h>
#include <math.h>
#include <float.h>
#include <fcntl.h>
#include <archive.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  archive_read_buffer
 Used as a buffer/state holder for _alpm_archive_fgets(). More...
 

Macros

#define _(s)   (char *)s
 
#define MALLOC(p, s, action)   do { p = malloc(s); if(p == NULL) { _alpm_alloc_fail(s); action; } } while(0)
 
#define CALLOC(p, l, s, action)   do { p = calloc(l, s); if(p == NULL) { _alpm_alloc_fail(l * s); action; } } while(0)
 
#define REALLOC(p, s, action)   do { void* np = realloc(p, s); if(np == NULL) { _alpm_alloc_fail(s); action; } else { p = np; } } while(0)
 
#define STRDUP(r, s, action)   do { if(s != NULL) { r = strdup(s); if(r == NULL) { _alpm_alloc_fail(strlen(s)); action; } } else { r = NULL; } } while(0)
 
#define STRNDUP(r, s, l, action)   do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { _alpm_alloc_fail(l); action; } } else { r = NULL; } } while(0)
 
#define FREE(p)   do { free(p); p = NULL; } while(0)
 
#define ASSERT(cond, action)   do { if(!(cond)) { action; } } while(0)
 
#define RET_ERR_VOID(handle, err)
 
#define RET_ERR(handle, err, ret)
 
#define GOTO_ERR(handle, err, label)
 
#define RET_ERR_ASYNC_SAFE(handle, err, ret)
 
#define CHECK_HANDLE(handle, action)   do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0)
 
#define ALPM_BUFFER_SIZE   8192
 Standard buffer size used throughout the library.
 
#define O_BINARY   0
 
#define OPEN(fd, path, flags)   do { fd = open(path, flags | O_BINARY); } while(fd == -1 && errno == EINTR)
 
#define SYMEXPORT   __attribute__((visibility("default")))
 
#define UNUSED   __attribute__((unused))
 

Functions

char * strsep (char **, const char *)
 Extracts tokens from a string.
 

Data Structure Documentation

◆ archive_read_buffer

struct archive_read_buffer

Used as a buffer/state holder for _alpm_archive_fgets().

Data Fields
char * block
char * block_offset
size_t block_size
char * line
char * line_offset
size_t line_size
size_t max_line_size
size_t real_line_size
int ret

Macro Definition Documentation

◆ _

◆ ALPM_BUFFER_SIZE

#define ALPM_BUFFER_SIZE   8192

Standard buffer size used throughout the library.

Referenced by _cache_mtree_open(), and build_filelist_from_mtree().

◆ ASSERT

#define ASSERT ( cond,
action )   do { if(!(cond)) { action; } } while(0)

Referenced by _package_changelog_open(), alpm_add_pkg(), alpm_compute_md5sum(), alpm_compute_sha256sum(), alpm_conflict_free(), alpm_db_add_cache_server(), alpm_db_add_server(), alpm_db_check_pgp_signature(), alpm_db_get_cache_servers(), alpm_db_get_group(), alpm_db_get_groupcache(), alpm_db_get_handle(), alpm_db_get_name(), alpm_db_get_pkg(), alpm_db_get_pkgcache(), alpm_db_get_servers(), alpm_db_get_siglevel(), alpm_db_get_usage(), alpm_db_get_valid(), alpm_db_remove_cache_server(), alpm_db_remove_server(), alpm_db_search(), alpm_db_set_cache_servers(), alpm_db_set_servers(), alpm_db_set_usage(), alpm_db_unregister(), alpm_db_update(), alpm_dep_compute_string(), alpm_dep_free(), alpm_depmissing_free(), alpm_fetch_pkgurl(), alpm_fileconflict_free(), alpm_find_dbs_satisfier(), alpm_logaction(), alpm_option_add_assumeinstalled(), alpm_option_add_cachedir(), alpm_option_add_hookdir(), alpm_option_remove_cachedir(), alpm_option_remove_hookdir(), alpm_option_set_dbext(), alpm_option_set_parallel_downloads(), alpm_pkg_changelog_close(), alpm_pkg_changelog_open(), alpm_pkg_changelog_read(), alpm_pkg_check_pgp_signature(), alpm_pkg_checkmd5sum(), alpm_pkg_free(), alpm_pkg_get_arch(), alpm_pkg_get_backup(), alpm_pkg_get_base(), alpm_pkg_get_base64_sig(), alpm_pkg_get_builddate(), alpm_pkg_get_checkdepends(), alpm_pkg_get_conflicts(), alpm_pkg_get_db(), alpm_pkg_get_depends(), alpm_pkg_get_desc(), alpm_pkg_get_filename(), alpm_pkg_get_files(), alpm_pkg_get_groups(), alpm_pkg_get_handle(), alpm_pkg_get_installdate(), alpm_pkg_get_isize(), alpm_pkg_get_licenses(), alpm_pkg_get_makedepends(), alpm_pkg_get_md5sum(), alpm_pkg_get_name(), alpm_pkg_get_optdepends(), alpm_pkg_get_origin(), alpm_pkg_get_packager(), alpm_pkg_get_provides(), alpm_pkg_get_reason(), alpm_pkg_get_replaces(), alpm_pkg_get_sha256sum(), alpm_pkg_get_sig(), alpm_pkg_get_size(), alpm_pkg_get_url(), alpm_pkg_get_validation(), alpm_pkg_get_version(), alpm_pkg_get_xdata(), alpm_pkg_has_scriptlet(), alpm_pkg_load(), alpm_pkg_mtree_close(), alpm_pkg_mtree_next(), alpm_pkg_mtree_open(), alpm_pkg_set_reason(), alpm_register_syncdb(), alpm_release(), alpm_remove_pkg(), alpm_sandbox_setup_child(), alpm_siglist_cleanup(), alpm_sync_get_new_version(), alpm_sync_sysupgrade(), alpm_trans_commit(), alpm_trans_get_add(), alpm_trans_get_flags(), alpm_trans_get_remove(), alpm_trans_init(), alpm_trans_interrupt(), alpm_trans_prepare(), alpm_trans_release(), alpm_unlock(), alpm_unregister_all_syncdbs(), commit_single_pkg(), compute_download_size(), compute_requiredby(), conflict_new(), curl_add_payload(), curl_check_finished_download(), finalize_download_file(), finalize_download_locations(), find_dl_candidates(), move_file(), prepare_resumable_downloads(), read_from_pipe(), and write_to_pipe().

◆ CALLOC

#define CALLOC ( p,
l,
s,
action )   do { p = calloc(l, s); if(p == NULL) { _alpm_alloc_fail(l * s); action; } } while(0)

◆ CHECK_HANDLE

#define CHECK_HANDLE ( handle,
action )   do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0)

Referenced by alpm_add_pkg(), alpm_checkconflicts(), alpm_checkdeps(), alpm_db_update(), alpm_fetch_pkgurl(), alpm_find_dbs_satisfier(), alpm_get_localdb(), alpm_get_syncdbs(), alpm_option_add_assumeinstalled(), alpm_option_add_cachedir(), alpm_option_add_hookdir(), alpm_option_get_architectures(), alpm_option_get_assumeinstalled(), alpm_option_get_cachedirs(), alpm_option_get_checkspace(), alpm_option_get_dbext(), alpm_option_get_dbpath(), alpm_option_get_default_siglevel(), alpm_option_get_dlcb(), alpm_option_get_dlcb_ctx(), alpm_option_get_eventcb(), alpm_option_get_eventcb_ctx(), alpm_option_get_fetchcb(), alpm_option_get_fetchcb_ctx(), alpm_option_get_gpgdir(), alpm_option_get_hookdirs(), alpm_option_get_ignoregroups(), alpm_option_get_ignorepkgs(), alpm_option_get_local_file_siglevel(), alpm_option_get_lockfile(), alpm_option_get_logcb(), alpm_option_get_logcb_ctx(), alpm_option_get_logfile(), alpm_option_get_noextracts(), alpm_option_get_noupgrades(), alpm_option_get_overwrite_files(), alpm_option_get_parallel_downloads(), alpm_option_get_progresscb(), alpm_option_get_progresscb_ctx(), alpm_option_get_questioncb(), alpm_option_get_questioncb_ctx(), alpm_option_get_remote_file_siglevel(), alpm_option_get_root(), alpm_option_get_sandboxuser(), alpm_option_get_usesyslog(), alpm_option_remove_architecture(), alpm_option_remove_assumeinstalled(), alpm_option_remove_cachedir(), alpm_option_remove_hookdir(), alpm_option_set_architectures(), alpm_option_set_assumeinstalled(), alpm_option_set_cachedirs(), alpm_option_set_checkspace(), alpm_option_set_dbext(), alpm_option_set_default_siglevel(), alpm_option_set_disable_dl_timeout(), alpm_option_set_disable_sandbox(), alpm_option_set_dlcb(), alpm_option_set_eventcb(), alpm_option_set_fetchcb(), alpm_option_set_gpgdir(), alpm_option_set_hookdirs(), alpm_option_set_local_file_siglevel(), alpm_option_set_logcb(), alpm_option_set_logfile(), alpm_option_set_parallel_downloads(), alpm_option_set_progresscb(), alpm_option_set_questioncb(), alpm_option_set_remote_file_siglevel(), alpm_option_set_sandboxuser(), alpm_option_set_usesyslog(), alpm_pkg_load(), alpm_register_syncdb(), alpm_release(), alpm_remove_pkg(), alpm_sync_sysupgrade(), alpm_trans_commit(), alpm_trans_get_add(), alpm_trans_get_flags(), alpm_trans_get_remove(), alpm_trans_init(), alpm_trans_interrupt(), alpm_trans_prepare(), alpm_trans_release(), and alpm_unregister_all_syncdbs().

◆ FREE

◆ GOTO_ERR

#define GOTO_ERR ( handle,
err,
label )
Value:
do { \
_alpm_log(handle, ALPM_LOG_DEBUG, "got error %d at %s (%s: %d) : %s\n", err, __func__, __FILE__, __LINE__, alpm_strerror(err)); \
(handle)->pm_errno = (err); \
goto label; } while(0)
const char * alpm_strerror(alpm_errno_t err)
Returns the string corresponding to an error number.
Definition error.c:35
@ ALPM_LOG_DEBUG
Debug.
Definition alpm.h:1500

Referenced by _cache_mtree_open(), alpm_db_update(), alpm_fetch_pkgurl(), alpm_pkg_get_sig(), build_filelist_from_mtree(), curl_add_payload(), curl_check_finished_download(), download_files(), and sync_db_populate().

◆ MALLOC

◆ O_BINARY

#define O_BINARY   0

◆ OPEN

#define OPEN ( fd,
path,
flags )   do { fd = open(path, flags | O_BINARY); } while(fd == -1 && errno == EINTR)

Referenced by commit_single_pkg().

◆ REALLOC

#define REALLOC ( p,
s,
action )   do { void* np = realloc(p, s); if(np == NULL) { _alpm_alloc_fail(s); action; } else { p = np; } } while(0)

Referenced by local_db_read(), and sync_db_read().

◆ RET_ERR

#define RET_ERR ( handle,
err,
ret )
Value:
do { \
_alpm_log(handle, ALPM_LOG_DEBUG, "returning error %d from %s (%s: %d) : %s\n", err, __func__, __FILE__, __LINE__, alpm_strerror(err)); \
(handle)->pm_errno = (err); \
return (ret); } while(0)

Referenced by _package_changelog_read(), add_fileconflict(), alpm_add_pkg(), alpm_db_add_cache_server(), alpm_db_add_server(), alpm_db_check_pgp_signature(), alpm_db_get_group(), alpm_db_get_pkg(), alpm_db_remove_cache_server(), alpm_db_remove_server(), alpm_db_search(), alpm_db_unregister(), alpm_fetch_pkgurl(), alpm_find_dbs_satisfier(), alpm_option_add_assumeinstalled(), alpm_option_add_cachedir(), alpm_option_add_hookdir(), alpm_option_remove_cachedir(), alpm_option_remove_hookdir(), alpm_option_set_dbext(), alpm_option_set_default_siglevel(), alpm_option_set_gpgdir(), alpm_option_set_local_file_siglevel(), alpm_option_set_logfile(), alpm_option_set_parallel_downloads(), alpm_option_set_remote_file_siglevel(), alpm_option_set_sandboxuser(), alpm_pkg_check_pgp_signature(), alpm_pkg_checkmd5sum(), alpm_pkg_get_sig(), alpm_pkg_load(), alpm_pkg_set_reason(), alpm_register_syncdb(), alpm_release(), alpm_remove_pkg(), alpm_sync_sysupgrade(), alpm_trans_commit(), alpm_trans_get_add(), alpm_trans_get_flags(), alpm_trans_get_remove(), alpm_trans_init(), alpm_trans_prepare(), alpm_trans_release(), alpm_unregister_all_syncdbs(), check_arch(), check_pkg_field_matches_db(), check_validity(), checkdbdir(), compute_download_size(), create_tempfile(), curl_check_finished_download(), curl_retry_next_server(), find_dl_candidates(), get_sync_dir(), init_gpgme(), key_search_keyserver(), load_packages(), load_pkg_for_entry(), local_db_create(), local_db_populate(), local_db_validate(), mount_point_list(), payload_download_fetchcb(), remove_package_files(), sync_db_populate(), and unlink_file().

◆ RET_ERR_ASYNC_SAFE

#define RET_ERR_ASYNC_SAFE ( handle,
err,
ret )
Value:
do { \
(handle)->pm_errno = (err); \
return (ret); } while(0)

Referenced by alpm_trans_interrupt(), and alpm_unlock().

◆ RET_ERR_VOID

#define RET_ERR_VOID ( handle,
err )
Value:
do { \
_alpm_log(handle, ALPM_LOG_DEBUG, "returning error %d from %s (%s: %d) : %s\n", err, __func__, __FILE__, __LINE__, alpm_strerror(err)); \
(handle)->pm_errno = (err); \
return; } while(0)

◆ STRDUP

◆ STRNDUP

#define STRNDUP ( r,
s,
l,
action )   do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { _alpm_alloc_fail(l); action; } } else { r = NULL; } } while(0)

◆ SYMEXPORT

#define SYMEXPORT   __attribute__((visibility("default")))

◆ UNUSED

#define UNUSED   __attribute__((unused))

Function Documentation

◆ strsep()

char * strsep ( char ** str,
const char * delims )

Extracts tokens from a string.

Replaces strset which is not portable (missing on Solaris). Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> Modifies str to point to the first character after the token if one is found, or NULL if one is not.

Parameters
strstring containing delimited tokens to parse
delimcharacter delimiting tokens in str
Returns
pointer to the first token in str if str is not NULL, NULL if str is NULL