[Reproducible-commits] [dpkg] 03/54: libdpkg: Add new str_fmt()
Mattia Rizzolo
mattia at debian.org
Fri Jan 15 18:53:58 UTC 2016
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to branch pu/reproducible_builds
in repository dpkg.
commit 302829039a4dba8a37fa31dfc0e06ca4a8e5a04b
Author: Guillem Jover <guillem at debian.org>
Date: Sun Oct 18 06:10:56 2015 +0200
libdpkg: Add new str_fmt()
This function is easier and more natural to use than m_asprintf(), and
we currently never use the returned length anyway.
---
lib/dpkg/dpkg.h | 1 +
lib/dpkg/libdpkg.map | 1 +
lib/dpkg/string.c | 23 ++++++++++++++++++++++-
lib/dpkg/string.h | 3 ++-
lib/dpkg/t/t-string.c | 19 +++++++++++++++++--
5 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 6b74a42..8aae4cf 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -116,6 +116,7 @@ DPKG_BEGIN_DECLS
#include <dpkg/progname.h>
#include <dpkg/ehandle.h>
#include <dpkg/report.h>
+#include <dpkg/string.h>
#include <dpkg/program.h>
/*** log.c ***/
diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map
index 34b226b..3b2aff7 100644
--- a/lib/dpkg/libdpkg.map
+++ b/lib/dpkg/libdpkg.map
@@ -79,6 +79,7 @@ LIBDPKG_PRIVATE {
str_match_end;
str_fnv_hash;
+ str_fmt;
str_escape_fmt;
str_strip_quotes;
str_quote_meta;
diff --git a/lib/dpkg/string.c b/lib/dpkg/string.c
index 25cee92..220e278 100644
--- a/lib/dpkg/string.c
+++ b/lib/dpkg/string.c
@@ -3,7 +3,7 @@
* string.c - string handling routines
*
* Copyright © 1995 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2008-2014 Guillem Jover <guillem at debian.org>
+ * Copyright © 2008-2015 Guillem Jover <guillem at debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -50,6 +50,27 @@ str_match_end(const char *str, const char *end)
}
/**
+ * Print formatted output to an allocated string.
+ *
+ * @param fmt The format string.
+ * @param ... The format arguments.
+ *
+ * @return The new allocated formatted output string (never NULL).
+ */
+char *
+str_fmt(const char *fmt, ...)
+{
+ va_list args;
+ char *str;
+
+ va_start(args, fmt);
+ m_vasprintf(&str, fmt, args);
+ va_end(args);
+
+ return str;
+}
+
+/**
* Escape format characters from a string.
*
* @param dst The destination string.
diff --git a/lib/dpkg/string.h b/lib/dpkg/string.h
index 4792a8b..927aeae 100644
--- a/lib/dpkg/string.h
+++ b/lib/dpkg/string.h
@@ -2,7 +2,7 @@
* libdpkg - Debian packaging suite library routines
* string.h - string handling routines
*
- * Copyright © 2008-2014 Guillem Jover <guillem at debian.org>
+ * Copyright © 2008-2015 Guillem Jover <guillem at debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,6 +56,7 @@ bool str_match_end(const char *str, const char *end);
unsigned int str_fnv_hash(const char *str);
+char *str_fmt(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
char *str_escape_fmt(char *dest, const char *src, size_t n);
char *str_quote_meta(const char *src);
char *str_strip_quotes(char *str);
diff --git a/lib/dpkg/t/t-string.c b/lib/dpkg/t/t-string.c
index 5b4310e..b5e3308 100644
--- a/lib/dpkg/t/t-string.c
+++ b/lib/dpkg/t/t-string.c
@@ -2,7 +2,7 @@
* libdpkg - Debian packaging suite library routines
* t-string.c - test string handling
*
- * Copyright © 2009-2011, 2014 Guillem Jover <guillem at debian.org>
+ * Copyright © 2009-2011, 2014-2015 Guillem Jover <guillem at debian.org>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -77,6 +77,20 @@ test_str_fnv_hash(void)
}
static void
+test_str_fmt(void)
+{
+ char *str;
+
+ str = str_fmt("%s", "abcde");
+ test_str(str, ==, "abcde");
+ free(str);
+
+ str = str_fmt("%d", 15);
+ test_str(str, ==, "15");
+ free(str);
+}
+
+static void
test_str_escape_fmt(void)
{
char buf[1024], *q;
@@ -184,11 +198,12 @@ test_str_strip_quotes(void)
static void
test(void)
{
- test_plan(48);
+ test_plan(50);
test_str_is_set();
test_str_match_end();
test_str_fnv_hash();
+ test_str_fmt();
test_str_escape_fmt();
test_str_quote_meta();
test_str_strip_quotes();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list