summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dpkg/libdpkg.map1
-rw-r--r--lib/dpkg/pkg-show.c33
-rw-r--r--lib/dpkg/pkg-show.h2
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index dc58738ea..33297a8bf 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -300,6 +300,7 @@ LIBDPKG_PRIVATE {
pkg_name_const;
pkg_source_version;
pkgbin_synopsis;
+ pkg_synopsis;
pkg_abbrev_want;
pkg_abbrev_status;
pkg_abbrev_eflag;
diff --git a/lib/dpkg/pkg-show.c b/lib/dpkg/pkg-show.c
index 569cbf5c2..67e5af404 100644
--- a/lib/dpkg/pkg-show.c
+++ b/lib/dpkg/pkg-show.c
@@ -224,6 +224,39 @@ pkgbin_synopsis(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len
}
/**
+ * Return a string representation of the package synopsis.
+ *
+ * The returned string must not be freed, and it's permanently allocated so
+ * can be used as long as the non-freeing memory pool has not been freed.
+ *
+ * It will try to use the installed version, otherwise it will fallback to
+ * use the available version.
+ *
+ * The package synopsis is the short description, but it is not NUL terminated,
+ * so the output len argument should be used to limit the string length.
+ *
+ * @param pkg The package to consider.
+ * @param[out] len The length of the synopsis string within the description.
+ *
+ * @return The string representation.
+ */
+const char *
+pkg_synopsis(const struct pkginfo *pkg, int *len)
+{
+ const char *pdesc;
+
+ pdesc = pkg->installed.description;
+ if (!pdesc)
+ pdesc = pkg->available.description;
+ if (!pdesc)
+ pdesc = _("(no description available)");
+
+ *len = strcspn(pdesc, "\n");
+
+ return pdesc;
+}
+
+/**
* Return a character abbreviated representation of the package want status.
*
* @param pkg The package to consider.
diff --git a/lib/dpkg/pkg-show.h b/lib/dpkg/pkg-show.h
index 9ef0ed459..4ac3f5d65 100644
--- a/lib/dpkg/pkg-show.h
+++ b/lib/dpkg/pkg-show.h
@@ -36,6 +36,8 @@ int pkg_sorter_by_nonambig_name_arch(const void *a, const void *b);
const char *pkgbin_synopsis(const struct pkginfo *pkg,
const struct pkgbin *pkgbin, int *len_ret);
+const char *
+pkg_synopsis(const struct pkginfo *pkg, int *len_ret);
int pkg_abbrev_want(const struct pkginfo *pkg);
int pkg_abbrev_status(const struct pkginfo *pkg);
int pkg_abbrev_eflag(const struct pkginfo *pkg);