XBPS Library API  0.19
The X Binary Package System
Functions
Utility functions

Functions

int xbps_cmpver (const char *pkg1, const char *pkg2)
 
char * xbps_file_hash (const char *file)
 
int xbps_file_hash_check (const char *file, const char *sha256)
 
int xbps_humanize_number (char *buf, int64_t bytes)
 
int xbps_mkpath (const char *path, mode_t mode)
 
bool xbps_pkg_arch_match (struct xbps_handle *xhp, const char *orig, const char *target)
 
bool xbps_pkg_has_rundeps (prop_dictionary_t dict)
 
char * xbps_pkg_index_files_plist (struct xbps_handle *xhp, const char *uri)
 
char * xbps_pkg_index_plist (struct xbps_handle *xhp, const char *uri)
 
int xbps_pkg_is_installed (struct xbps_handle *xhp, const char *pkg)
 
char * xbps_pkg_name (const char *pkg)
 
const char * xbps_pkg_revision (const char *pkg)
 
const char * xbps_pkg_version (const char *pkg)
 
int xbps_pkgpattern_match (const char *pkgver, const char *pattern)
 
char * xbps_pkgpattern_name (const char *pattern)
 
const char * xbps_pkgpattern_version (const char *pattern)
 
bool xbps_repository_is_remote (const char *uri)
 
char * xbps_xasprintf (const char *fmt,...)
 

Detailed Description

Function Documentation

int xbps_cmpver ( const char *  pkg1,
const char *  pkg2 
)

Compares package version strings.

The package version is defined by: ${VERSION}[_${REVISION}].

Parameters
[in]pkg1a package version string.
[in]pkg2a package version string.
Returns
-1, 0 or 1 depending if pkg1 is less than, equal to or greater than pkg2.

Definition at line 276 of file dewey.c.

char* xbps_file_hash ( const char *  file)

Returns a string with the sha256 hash for the file specified by file.

Parameters
[in]filePath to a file.
Returns
A pointer to a malloc(3)ed string, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needed.

Definition at line 65 of file util_hash.c.

Referenced by xbps_file_hash_check(), and xbps_register_pkg().

+ Here is the caller graph for this function:

int xbps_file_hash_check ( const char *  file,
const char *  sha256 
)

Compares the sha256 hash of the file file with the sha256 string specified by sha256.

Parameters
[in]filePath to a file.
[in]sha256SHA256 hash to compare.
Returns
0 if file and sha256 have the same hash, ERANGE if it differs, or any other errno value on error.

Definition at line 124 of file util_hash.c.

References xbps_file_hash().

Referenced by xbps_remove_pkg_files().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int xbps_humanize_number ( char *  buf,
int64_t  bytes 
)

Converts the 64 bits signed number specified in bytes to a human parsable string buffer pointed to buf.

Parameters
[out]bufBuffer to store the resulting string. At least it should have space for 6 chars.
[in]bytes64 bits signed number to convert.
Returns
A negative number is returned on error, 0 otherwise.

Definition at line 322 of file util.c.

int xbps_mkpath ( const char *  path,
mode_t  mode 
)

Creates a directory (and required components if necessary).

Parameters
[in]pathPath for final directory.
[in]modeMode for final directory (0755 if not specified).
Returns
0 on success, -1 on error and errno set appropiately.

Definition at line 42 of file mkpath.c.

bool xbps_pkg_arch_match ( struct xbps_handle xhp,
const char *  orig,
const char *  target 
)

Returns true if provided string is valid for target architecture.

Parameters
[in]xhpThe pointer to an xbps_handle struct.
[in]origArchitecture to match.
[in]targetIf not NULL, orig will be matched against it rather than returned value of uname(2).
Returns
True on match, false otherwise.

Definition at line 261 of file util.c.

bool xbps_pkg_has_rundeps ( prop_dictionary_t  dict)

Checks if a package has run dependencies.

Parameters
[in]dictPackage dictionary.
Returns
True if package has run dependencies, false otherwise.

Definition at line 246 of file util.c.

char* xbps_pkg_index_files_plist ( struct xbps_handle xhp,
const char *  uri 
)

Returns the full path to a repository package index files plist file, as specified by uri.

Parameters
[in]xhpThe pointer to an xbps_handle struct.
[in]uriRepository URI.
Returns
A pointer to a malloc(3)ed string, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needded.

Definition at line 201 of file util.c.

References xbps_repository_is_remote(), and xbps_xasprintf().

+ Here is the call graph for this function:

char* xbps_pkg_index_plist ( struct xbps_handle xhp,
const char *  uri 
)

Gets the full path to a repository package index plist file, as specified by uri.

Parameters
[in]xhpThe pointer to an xbps_handle struct.
[in]uriRepository URI.
Returns
A pointer to a malloc(3)d string, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needed.

Definition at line 189 of file util.c.

References xbps_repository_is_remote(), and xbps_xasprintf().

+ Here is the call graph for this function:

int xbps_pkg_is_installed ( struct xbps_handle xhp,
const char *  pkg 
)

Checks if a package is currently installed by matching pkg.

Parameters
[in]xhpThe pointer to an xbps_handle struct.
[in]pkgPackage name, version pattern or exact pkg to match.
Returns
-1 on error (errno set appropiately), 0 if pkg didn't match installed package, 1 if pkg pattern fully matched installed package.

Definition at line 63 of file util.c.

References xbps_pkg_state_dictionary(), xbps_pkgdb_get_pkg(), and xbps_pkgdb_get_virtualpkg().

+ Here is the call graph for this function:

char* xbps_pkg_name ( const char *  pkg)

Gets the name of a package string. Package strings are composed by a <pkgname>/<version> pair and separated by the minus sign, i.e foo-2.0.

Parameters
[in]pkgPackage string.
Returns
A pointer to a malloc(3)d string, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needed.

Definition at line 115 of file util.c.

Referenced by xbps_remove_pkg(), and xbps_remove_pkg_files().

+ Here is the caller graph for this function:

const char* xbps_pkg_revision ( const char *  pkg)

Gets the package version revision in a package string.

Parameters
[in]pkgPackage string, i.e foo-2.0_1.
Returns
A string with the revision number, NULL if it couldn't find the revision component.

Definition at line 101 of file util.c.

const char* xbps_pkg_version ( const char *  pkg)

Gets the package version in a package string, i.e foo-2.0.

Parameters
[in]pkgPackage string.
Returns
A string with the version string, NULL if it couldn't find the version component.

Definition at line 87 of file util.c.

Referenced by xbps_pkgdb_remove_pkg(), xbps_remove_pkg(), xbps_remove_pkg_files(), xbps_rindex_get_pkg(), xbps_rindex_get_virtualpkg(), and xbps_rpool_get_pkg().

+ Here is the caller graph for this function:

int xbps_pkgpattern_match ( const char *  pkgver,
const char *  pattern 
)

Package pattern matching.

Parameters
[in]pkgverPackage name/version, i.e `foo-1.0'.
[in]patternPackage pattern to match against pkgver. There are 3 strategies for version matching:
  • simple compare: pattern equals to pkgver.
  • shell wildcards: see fnmatch(3).
  • relational dewey matching: '>' '<' '>=' '<='.
Returns
1 if pkgver is matched against pattern, 0 if no match.

Definition at line 298 of file util.c.

Referenced by xbps_match_any_virtualpkg_in_rundeps().

+ Here is the caller graph for this function:

char* xbps_pkgpattern_name ( const char *  pattern)

Gets a the package name of a package pattern string specified by the pattern argument.

Parameters
[in]patternA package pattern. Package patterns are composed by looking at '><=' to split components, i.e foo>=2.0, blah<1.0, blob==2.0, etc.
Returns
A pointer to a malloc(3)ed string with the package name, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needed.

Definition at line 138 of file util.c.

const char* xbps_pkgpattern_version ( const char *  pattern)

Gets the package version of a package pattern string specified by the pattern argument.

Parameters
[in]patternA package pattern. The same rules in xbps_get_pkgpattern_name() apply here.
Returns
A string with the pattern version, NULL otherwise and errno is set appropiately.

Definition at line 162 of file util.c.

Referenced by xbps_pkgdb_remove_pkg(), xbps_pkgdb_replace_pkg(), xbps_rindex_get_pkg(), xbps_rindex_get_virtualpkg(), and xbps_rpool_get_pkg().

+ Here is the caller graph for this function:

bool xbps_repository_is_remote ( const char *  uri)

Checks if the URI specified by uri is remote or local.

Parameters
[in]uriURI string.
Returns
true if URI is remote, false if local.

Definition at line 50 of file util.c.

Referenced by xbps_pkg_index_files_plist(), and xbps_pkg_index_plist().

+ Here is the caller graph for this function:

char* xbps_xasprintf ( const char *  fmt,
  ... 
)

Returns a string by concatenating its variable argument list as specified by the format string fmt.

Parameters
[in]fmtFormat string, see printf(3).
Returns
A pointer to a malloc(3)ed string, NULL otherwise and errno is set appropiately. The pointer should be free(3)d when it's no longer needed.

Definition at line 278 of file util.c.

Referenced by xbps_configure_pkg(), xbps_fetch_file(), xbps_init(), xbps_match_any_virtualpkg_in_rundeps(), xbps_pkg_exec_buffer(), xbps_pkg_index_files_plist(), xbps_pkg_index_plist(), xbps_pkgdb_update(), xbps_register_pkg(), xbps_remove_pkg(), and xbps_remove_pkg_files().

+ Here is the caller graph for this function: