summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@opencompositing.org>2008-08-18 15:32:31 +0200
committerDennis kasprzyk <onestone@opencompositing.org>2008-08-18 15:32:31 +0200
commit79d78d3f60e683411a075fe44fe4ab862d0fadc6 (patch)
treed970c542e2a67264ac6ca61ba814f6b44408b255 /src/string.cpp
parentfa7e9361989282eddfc3012ffc392fadebf2b3c5 (diff)
downloadunity-window-decorator-79d78d3f60e683411a075fe44fe4ab862d0fadc6.tar.gz
unity-window-decorator-79d78d3f60e683411a075fe44fe4ab862d0fadc6.tar.bz2
Fragment interface C++ port (not tested).
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp
new file mode 100644
index 0000000..fdf71b3
--- /dev/null
+++ b/src/string.cpp
@@ -0,0 +1,56 @@
+#include <compiz-core.h>
+
+CompString compPrintf (const char *format, ...)
+{
+ va_list ap;
+ CompString rv;
+
+ va_start (ap, format);
+ rv = compPrintf(format, ap);
+ va_end (ap);
+
+ return rv;
+}
+
+CompString compPrintf (const char *format, va_list ap)
+{
+ va_list aq;
+ unsigned int size = strlen (format) + 1;
+ int n;
+ char *str;
+
+ if (!format)
+ return CompString ("");
+
+ str = new char[size];
+
+ if (!str)
+ return CompString ("");
+
+ while (1)
+ {
+ /* Try to print in the allocated space. */
+ va_copy (aq, ap);
+ n = vsnprintf (str, size, format, aq);
+ va_end (aq);
+
+ /* If that worked, leave the loop. */
+ if (n > -1 && n < (int) size)
+ break;
+
+ /* Else try again with more space. */
+ if (n > -1) /* glibc 2.1 */
+ size = n + 1; /* precisely what is needed */
+ else /* glibc 2.0 */
+ size++; /* one more than the old size */
+
+ delete str;
+ str = new char[size];
+
+ if (str)
+ {
+ return CompString ("");
+ }
+ }
+ return CompString ("");
+}