From: "Ronald S. Bultje" <[email protected]>
---
Here my initial twist about it, ideally I'd consider moving os_support
in libavu and include it automagically from config.h
configure | 2 ++
libavutil/avstring.c | 24 ++++++++++++++++++++++++
libavutil/os_support.h | 30 ++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 0 deletions(-)
create mode 100644 libavutil/os_support.h
diff --git a/configure b/configure
index 37980f0..06ac1d7 100755
--- a/configure
+++ b/configure
@@ -1153,6 +1153,7 @@ HAVE_LIST="
setrlimit
Sleep
sndio_h
+ snprintf
socklen_t
soundcard_h
strerror_r
@@ -2896,6 +2897,7 @@ check_func mmap
check_func ${malloc_prefix}posix_memalign && enable posix_memalign
check_func_headers malloc.h _aligned_malloc && enable aligned_malloc
check_func setrlimit
+check_func snprintf
check_func strerror_r
check_func strptime
check_func strtok_r
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 11f3a7c..e975890 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -26,6 +26,30 @@
#include "avstring.h"
#include "mem.h"
+#if !HAVE_SNPRINTF
+#ifdef _MSC_VER
+#define vsnprintf _vsnprintf
+#endif
+
+int snprintf(char *buffer, size_t bufsize, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ if ((int)bufsize <= 0) return -1;
+ va_start(ap, fmt);
+ ret = vsnprintf(buffer, bufsize-1, fmt, ap);
+ if (ret < 0) {
+ buffer[bufsize - 1] = '\0';
+ ret = bufsize - 1;
+ }
+ va_end(ap);
+ return ret;
+}
+#define snprintf(...) ff_snprintf(__VA_ARGS__)
+#endif
+
+
int av_strstart(const char *str, const char *pfx, const char **ptr)
{
while (*pfx && *pfx == *str) {
diff --git a/libavutil/os_support.h b/libavutil/os_support.h
new file mode 100644
index 0000000..efecfe6
--- /dev/null
+++ b/libavutil/os_support.h
@@ -0,0 +1,30 @@
+/*
+ * various OS-feature replacement utilities
+ * copyright (c) 2012 Ronald S. Bultje
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_OS_SUPPORT_H
+#define AVUTIL_OS_SUPPORT_H
+
+#if !HAVE_SNPRINTF
+int ff_snprintf(char *buffer, size_t bufsize, const char *fmt, ...);
+#define snprintf(...) ff_snprintf(__VA_ARGS__)
+#endif
+
+#endif /* AVUTIL_OS_SUPPORT_H */
--
1.7.8.rc1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel