public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/openrc:master commit in: src/includes/
@ 2015-12-14 17:38 William Hubbs
  0 siblings, 0 replies; 5+ messages in thread
From: William Hubbs @ 2015-12-14 17:38 UTC (permalink / raw
  To: gentoo-commits

commit:     065f034059d7ca26bbb985158c5d361ff75df186
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Mon Dec 14 17:37:39 2015 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Dec 14 17:37:39 2015 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=065f0340

format fix

 src/includes/helpers.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 4352858..aaf4e3a 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -1,7 +1,7 @@
 /*
-  helpers.h
-  This is private to us and not for user consumption
-*/
+ * helpers.h
+ * This is private to us and not for user consumption
+ */
 
 /*
  * Copyright (c) 2007-2009 Roy Marples <roy@marples.name>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/openrc:master commit in: src/includes/
@ 2018-02-10 20:52 William Hubbs
  0 siblings, 0 replies; 5+ messages in thread
From: William Hubbs @ 2018-02-10 20:52 UTC (permalink / raw
  To: gentoo-commits

commit:     68b9b0bc2a11d144870d14fcb8ac24e6c9c63354
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sat Feb 10 20:09:22 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Feb 10 20:49:40 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=68b9b0bc

xasprintf: exit if return value of vsnprintf is invalid

 src/includes/helpers.h | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 3657ee74..6e0ad19f 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -158,15 +158,12 @@ _unused static int xasprintf(char **strp, const char *fmt, ...)
 		va_start(ap, fmt);
 		len = vsnprintf(ret, len + 1, fmt, ap);
 		va_end(ap);
-		if (len >= memlen) {
-			/* Give up! */
-			free(ret);
-			return -1;
-		}
 	}
-	if (len < 0) {
+	if (len < 0 || len >= memlen) {
+		/* Give up! */
+		fprintf(stderr, "xasprintf: unable to format a buffer\n");
 		free(ret);
-		return -1;
+		exit(1);
 	}
 	*strp = ret;
 	return len;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/openrc:master commit in: src/includes/
@ 2018-02-10 20:52 William Hubbs
  0 siblings, 0 replies; 5+ messages in thread
From: William Hubbs @ 2018-02-10 20:52 UTC (permalink / raw
  To: gentoo-commits

commit:     287d71bd2591ddec73efe356db081020e65cd922
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Fri Feb  9 21:35:12 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Fri Feb  9 21:35:12 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=287d71bd

helpers.h: style fix

 src/includes/helpers.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 1a00d3d0..8d8b16e8 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -96,8 +96,10 @@ _unused static char *xstrdup(const char *str)
 
 #undef ERRX
 
-/* basename_c never modifies the argument. As such, if there is a trailing
- * slash then an empty string is returned. */
+/*
+ * basename_c never modifies the argument. As such, if there is a trailing
+ * slash then an empty string is returned.
+ */
 _unused static const char *basename_c(const char *path)
 {
 	const char *slash = strrchr(path, '/');


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/openrc:master commit in: src/includes/
@ 2018-02-10 20:52 William Hubbs
  0 siblings, 0 replies; 5+ messages in thread
From: William Hubbs @ 2018-02-10 20:52 UTC (permalink / raw
  To: gentoo-commits

commit:     4616f8f809ee8566904ca37f2b8bf0409a487475
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Fri Feb  9 22:27:12 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Fri Feb  9 22:27:12 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=4616f8f8

helpers.h: add xasprintf function

This is our own version of asprintf(). This original code was written by
Mike Frysinger, and I was able to modify it to use our memory helper
functions.

We need a version of this code because it is not available on glibc at
least without defining _GNU_SOURCE, and I would rather not do that.

This is the first step in improving string handling in OpenRC for #207.

 src/includes/helpers.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 8d8b16e8..3657ee74 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -53,6 +53,7 @@
 	} while (/* CONSTCOND */ 0)
 #endif
 
+#include <stdarg.h>
 #include <stdbool.h>
 #include <sys/stat.h>
 
@@ -123,4 +124,52 @@ _unused static bool existss(const char *pathname)
 	return (stat(pathname, &buf) == 0 && buf.st_size != 0);
 }
 
+/*
+ * This is an OpenRC specific version of the asprintf() function.
+ * We do this to avoid defining the _GNU_SOURCE feature test macro on
+ * glibc systems and to insure that we have a consistent function across
+ * platforms. This also allows us to call our xmalloc and xrealloc
+ * functions to handle memory allocation.
+ * this function was originally written by Mike Frysinger.
+ */
+_unused static int xasprintf(char **strp, const char *fmt, ...)
+{
+	va_list ap;
+	int len;
+	int memlen;
+	char *ret;
+
+	/*
+	 * Start with a buffer size that should cover the vast majority of uses
+	 * (path construction).
+	 */
+	memlen = 4096;
+	ret = xmalloc(memlen);
+
+	va_start(ap, fmt);
+	len = vsnprintf(ret, memlen, fmt, ap);
+	va_end(ap);
+	if (len >= memlen) {
+		/*
+		 * Output was truncated, so increase buffer to exactly what we need.
+		 */
+		memlen = len + 1;
+		ret = xrealloc(ret, memlen);
+		va_start(ap, fmt);
+		len = vsnprintf(ret, len + 1, fmt, ap);
+		va_end(ap);
+		if (len >= memlen) {
+			/* Give up! */
+			free(ret);
+			return -1;
+		}
+	}
+	if (len < 0) {
+		free(ret);
+		return -1;
+	}
+	*strp = ret;
+	return len;
+}
+
 #endif


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/openrc:master commit in: src/includes/
@ 2018-02-14 23:37 William Hubbs
  0 siblings, 0 replies; 5+ messages in thread
From: William Hubbs @ 2018-02-14 23:37 UTC (permalink / raw
  To: gentoo-commits

commit:     0110487722646ebf9bc2c4e12b4b4a3c358cb10d
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sat Feb 10 22:48:22 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Feb 10 22:48:22 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=01104877

helpers.h: silence compiler warnings about xasprintf

 src/includes/helpers.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/includes/helpers.h b/src/includes/helpers.h
index 6e0ad19f..037a7859 100644
--- a/src/includes/helpers.h
+++ b/src/includes/helpers.h
@@ -28,9 +28,11 @@
 #if __GNUC__ > 2 || defined(__INTEL_COMPILER)
 # define _dead __attribute__((__noreturn__))
 # define _unused __attribute__((__unused__))
+# define _xasprintf(a, b)  __attribute__((__format__(__printf__, a, b)))
 #else
 # define _dead
 # define _unused
+# define _xasprintf(a, b)
 #endif
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
@@ -132,7 +134,7 @@ _unused static bool existss(const char *pathname)
  * functions to handle memory allocation.
  * this function was originally written by Mike Frysinger.
  */
-_unused static int xasprintf(char **strp, const char *fmt, ...)
+_unused _xasprintf(2,3) static int xasprintf(char **strp, const char *fmt, ...)
 {
 	va_list ap;
 	int len;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-02-14 23:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-14 23:37 [gentoo-commits] proj/openrc:master commit in: src/includes/ William Hubbs
  -- strict thread matches above, loose matches on Subject: below --
2018-02-10 20:52 William Hubbs
2018-02-10 20:52 William Hubbs
2018-02-10 20:52 William Hubbs
2015-12-14 17:38 William Hubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox