Basic runnable version; no functionality yet.
[udpgate.git] / configure.ac
index af13c21..d6cc911 100644 (file)
@@ -120,6 +120,37 @@ AH_BOTTOM([
 #include <glib/gtypes.h>       /* for 'gchar' */
 #define G_LOG_DOMAIN ((const gchar *)"UDPForward")
 
+/**
+ * udpforward_printf_alloca:
+ * @format: Format string. See the sprintf() documentation.
+ * @args...: Arguments for @format. See the sprintf() documentation.
+ *
+ * Format the given format string @format as in sprintf().
+ * Output buffer is allocated automatically and it does not need to be deallocated
+ * manually as it is managed by g_alloca().
+ *
+ * @Returns: Formatted output string located in g_alloca() memory.
+ */
+#define udpforward_printf_alloca(format,args...) ({ \
+               gsize _udpforward_printf_alloca_size=udpforward_nv_printf_string_upper_bound((format) , ## args); \
+               gchar *_udpforward_printf_alloca_r=g_alloca(_udpforward_printf_alloca_size); \
+               g_snprintf(_udpforward_printf_alloca_r,_udpforward_printf_alloca_size,(format) , ## args); \
+               (const gchar *)_udpforward_printf_alloca_r; \
+               })
+#include <stdarg.h>
+#include <glib/gmessages.h>    /* for g_printf_string_upper_bound() */
+static inline gsize udpforward_nv_printf_string_upper_bound(const gchar *format,...) G_GNUC_PRINTF(1,0) G_GNUC_UNUSED;
+static inline gsize udpforward_nv_printf_string_upper_bound(const gchar *format,...)
+{
+va_list ap;
+gsize r;
+
+       va_start(ap,format);
+       r=g_printf_string_upper_bound(format,ap);
+       va_end(ap);
+       return r;
+}
+
 #endif /* !_UDPFORWARD_CONFIG_H */
 ])