summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2007-12-03 11:28:39 +0000
committerBastien Nocera <hadess@src.gnome.org>2007-12-03 11:28:39 +0000
commit41b0fa00554cb45cf6845b73fc5adc25644a07a7 (patch)
treeec4d76a4e43522f20a3fbd7ba6b06510a5038b92 /lib
downloadtotem-pl-parser-41b0fa00554cb45cf6845b73fc5adc25644a07a7.tar.gz
Moved from Totem, export mini plparser for use in the browser plugin
2007-12-03 Bastien Nocera <hadess@hadess.net> * *: Moved from Totem, export mini plparser for use in the browser plugin (Closes: #462153) svn path=/trunk/; revision=2
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am15
-rw-r--r--lib/asprintf.c57
-rw-r--r--lib/totem_internal.h16
3 files changed, 88 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..1daf961
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = \
+ libtotem_glibc.la
+
+common_defines = \
+ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -DDATADIR=\""$(datadir)"\" \
+ $(DISABLE_DEPRECATED)
+
+noinst_HEADERS = totem_internal.h
+
+libtotem_glibc_la_SOURCES =
+libtotem_glibc_la_LIBADD = @LTLIBOBJS@
+
+EXTRA_DIST = asprintf.c
+
diff --git a/lib/asprintf.c b/lib/asprintf.c
new file mode 100644
index 0000000..da4e515
--- /dev/null
+++ b/lib/asprintf.c
@@ -0,0 +1,57 @@
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/varargs.h>
+
+
+int totem_private_asprintf(char **out, const char *fmt, ...)
+{
+ va_list ap;
+ int ret_status = EOF;
+ char dir_name[2001];
+ char file_name[2000];
+ FILE *fp = NULL;
+ char *work = NULL;
+
+ va_start(ap, fmt);
+
+ /* Warning: tmpfile() does not work well on Windows (MinGW)
+ * if user does not have write access on the drive where
+ * working dir is? */
+#ifdef __MINGW32__
+ /* file_name = G_tempfile(); */
+ GetTempPath ( 2000, dir_name );
+ GetTempFileName ( dir_name, "asprintf", 0, file_name );
+ fp = fopen ( file_name, "w+" );
+#else
+ fp = tmpfile();
+#endif /* __MINGW32__ */
+
+ if ( fp ) {
+ int count;
+
+ count = vfprintf(fp, fmt, ap);
+ if (count >= 0) {
+ work = calloc(count + 1, sizeof(char));
+ if (work != NULL) {
+ rewind(fp);
+ ret_status = fread(work, sizeof(char), count, fp);
+ if (ret_status != count) {
+ ret_status = EOF;
+ free(work);
+ work = NULL;
+ }
+ }
+ }
+ fclose(fp);
+#ifdef __MINGW32__
+ unlink ( file_name );
+#endif /* __MINGW32__ */
+ }
+ va_end(ap);
+ *out = work;
+
+ return ret_status;
+}
+
diff --git a/lib/totem_internal.h b/lib/totem_internal.h
new file mode 100644
index 0000000..9e8f255
--- /dev/null
+++ b/lib/totem_internal.h
@@ -0,0 +1,16 @@
+
+#include "config.h"
+
+/* replacement of asprintf & vasprintf */
+#ifndef HAVE_ASPRINTF
+#define HAVE_ASPRINTF
+#ifdef __GNUC__
+ #define asprintf(STRINGPP, FORMAT, ARGS...) totem_private_asprintf((STRINGPP), FORMAT, ##ARGS)
+#elif defined (_MSC_VER)
+ #define asprintf(STRINGPP, FORMATARGS) totem_private_asprintf((STRINGPP), FORMATARGS)
+#else
+ #define asprintf(STRINGPP, FORMAT, ...) totem_private_asprintf((STRINGPP), FORMAT, __VA_ARGS__)
+#endif
+int totem_private_asprintf(char **string, const char *format, ...);
+#endif
+