[MPlayer-cvslog] r32970 - in trunk: Makefile mp_strings.c mp_strings.h

cboesch subversion at mplayerhq.hu
Sat Feb 26 12:55:03 CET 2011


Author: cboesch
Date: Sat Feb 26 12:55:02 2011
New Revision: 32970

Log:
Add mp_strings.c with mp_asprintf function.

Added:
   trunk/mp_strings.c
   trunk/mp_strings.h
Modified:
   trunk/Makefile

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Fri Feb 25 13:26:31 2011	(r32969)
+++ trunk/Makefile	Sat Feb 26 12:55:02 2011	(r32970)
@@ -301,6 +301,7 @@ SRCS_COMMON = asxparser.c \
               m_option.c \
               m_struct.c \
               mp_msg.c \
+              mp_strings.c \
               mpcommon.c \
               parser-cfg.c \
               path.c \

Added: trunk/mp_strings.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/mp_strings.c	Sat Feb 26 12:55:02 2011	(r32970)
@@ -0,0 +1,50 @@
+/*
+ * Strings utilities
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include "mp_strings.h"
+
+char *mp_asprintf(const char *fmt, ...)
+{
+    char *p = NULL;
+    va_list va, va_bak;
+    int len;
+
+    va_start(va, fmt);
+    va_copy(va_bak, va);
+
+    len = vsnprintf(NULL, 0, fmt, va);
+    if (len < 0)
+        goto end;
+
+    p = malloc(len + 1);
+    if (!p)
+        goto end;
+
+    len = vsnprintf(p, len + 1, fmt, va_bak);
+    if (len < 0)
+        free(p), p = NULL;
+
+end:
+    va_end(va);
+    return p;
+}

Added: trunk/mp_strings.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/mp_strings.h	Sat Feb 26 12:55:02 2011	(r32970)
@@ -0,0 +1,26 @@
+/*
+ * Strings utilities
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_MP_STRINGS_H
+#define MPLAYER_MP_STRINGS_H
+
+char *mp_asprintf(const char *fmt, ...);
+
+#endif /* !MPLAYER_MP_STRINGS_H */


More information about the MPlayer-cvslog mailing list