[PATCH] libosmocore[master]: pseudotalloc: Add poor implementation of talloc_asprintf

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Sun Jun 18 11:31:01 UTC 2017


Review at  https://gerrit.osmocom.org/2961

pseudotalloc: Add poor implementation of talloc_asprintf

fsm.c uses this function. When compiled with --enable-embedded, it
triggers a warning:

fsm.c: In function 'osmo_fsm_inst_alloc':
fsm.c:213:4: warning: implicit declaration of function 'talloc_asprintf' [-Wimplicit-function-declaration]
    fi->name = talloc_asprintf(fi, "%s(%s)", fsm->name, id);

Change-Id: I61cd83d4c8570af1e452c945ac6f194baf7e6ac4
---
M src/pseudotalloc/pseudotalloc.c
M src/pseudotalloc/talloc.h
2 files changed, 20 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/2961/1

diff --git a/src/pseudotalloc/pseudotalloc.c b/src/pseudotalloc/pseudotalloc.c
index fe7f1ed..5c9c498 100644
--- a/src/pseudotalloc/pseudotalloc.c
+++ b/src/pseudotalloc/pseudotalloc.c
@@ -5,6 +5,7 @@
 
 #include "talloc.h"
 #include <string.h>
+#include <stdio.h>
 
 void *_talloc_zero(const void *ctx, size_t size, const char *name)
 {
@@ -61,3 +62,21 @@
 {
 	return talloc_zero_size(ctx, el_size * count);
 }
+
+char *talloc_asprintf(const void *ctx, const char *fmt, ...) {
+	char *buf;
+	size_t len = 512;
+	va_list args;
+	va_start(args, fmt);
+
+	while (1) {
+		buf = talloc_size(ctx, len);
+		if (len < vsprintf(buf, fmt, args))
+			break;
+		talloc_free(buf);
+		len *= 2;
+	}
+
+	va_end(args);
+	return buf;
+}
diff --git a/src/pseudotalloc/talloc.h b/src/pseudotalloc/talloc.h
index c7127de..f4c0a74 100644
--- a/src/pseudotalloc/talloc.h
+++ b/src/pseudotalloc/talloc.h
@@ -39,4 +39,4 @@
 			 size_t el_size,
 			 unsigned count,
 			 const char *name);
-
+char *talloc_asprintf(const void *ctx, const char *fmt, ...);

-- 
To view, visit https://gerrit.osmocom.org/2961
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I61cd83d4c8570af1e452c945ac6f194baf7e6ac4
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list