#ifndef UTIL_H
#define UTIL_H 1
+#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
#include "compiler.h"
+#ifndef va_copy
+#ifdef __va_copy
+#define va_copy __va_copy
+#else
+#define va_copy(dst, src) ((dst) = (src))
+#endif
+#endif
+
#ifndef __cplusplus
/* Build-time assertion for use in a statement context. */
#define BUILD_ASSERT(EXPR) \
char *xmemdup0(const char *, size_t);
char *xstrdup(const char *);
char *xasprintf(const char *format, ...) PRINTF_FORMAT(1, 2);
+char *xvasprintf(const char *format, va_list) PRINTF_FORMAT(1, 0);
+
+#ifndef HAVE_STRLCPY
+void strlcpy(char *dst, const char *src, size_t size);
+#endif
void ofp_fatal(int err_no, const char *format, ...)
PRINTF_FORMAT(2, 3) NO_RETURN;
}
char *
-xasprintf(const char *format, ...)
+xvasprintf(const char *format, va_list args)
{
- va_list args;
+ va_list args2;
size_t needed;
char *s;
- va_start(args, format);
+ va_copy(args2, args);
needed = vsnprintf(NULL, 0, format, args);
- va_end(args);
s = xmalloc(needed + 1);
+ vsnprintf(s, needed + 1, format, args2);
+ va_end(args2);
+
+ return s;
+}
+
+char *
+xasprintf(const char *format, ...)
+{
+ va_list args;
+ char *s;
+
va_start(args, format);
- vsnprintf(s, needed + 1, format, args);
+ s = xvasprintf(format, args);
va_end(args);
return s;
}
+void
+strlcpy(char *dst, const char *src, size_t size)
+{
+ if (size > 0) {
+ size_t n = strlen(src);
+ size_t n_copy = MIN(n, size - 1);
+ memcpy(dst, src, n_copy);
+ dst[n_copy] = '\0';
+ }
+}
+
void
ofp_fatal(int err_no, const char *format, ...)
{
[AC_CHECK_LIB([socket], [connect])
AC_SEARCH_LIBS([gethostbyname], [resolv], [RESOLVER_LIBS=-lresolv])])
+
dnl Runs the checks required to include the headers in include/ and
dnl link against lib/libopenflow.a.
AC_DEFUN([OFP_CHECK_LIBOPENFLOW],
AC_REQUIRE([OFP_CHECK_OPENSSL])
AC_REQUIRE([OFP_CHECK_SNAT])
AC_REQUIRE([OFP_CHECK_FAULT_LIBS])
- AC_REQUIRE([OFP_CHECK_SOCKET_LIBS])])
+ AC_REQUIRE([OFP_CHECK_SOCKET_LIBS])
+ AC_CHECK_FUNCS([strlcpy])])