if (!OVS_LIKELY(CONDITION)) { \
ovs_assert_failure(SOURCE_LOCATOR, __func__, #CONDITION); \
}
-void ovs_assert_failure(const char *, const char *, const char *) NO_RETURN;
+NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
/* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes
* anything other than an outermost "const" or "volatile" qualifier.
((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER))), \
(TYPE) (POINTER))
-extern const char *program_name;
+extern char *program_name;
#define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
#ifdef __GNUC__
#define CACHE_LINE_SIZE 64
BUILD_ASSERT_DECL(IS_POW2(CACHE_LINE_SIZE));
+static inline void
+ovs_prefetch_range(const void *start, size_t size)
+{
+ const char *addr = (const char *)start;
+ size_t ofs;
+
+ for (ofs = 0; ofs < size; ofs += CACHE_LINE_SIZE) {
+ OVS_PREFETCH(addr + ofs);
+ }
+}
+
#ifndef MIN
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#endif
#define ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER) \
((OBJECT) = OBJECT_CONTAINING(POINTER, OBJECT, MEMBER), (void) 0)
+/* As explained in the comment above OBJECT_OFFSETOF(), non-GNUC compilers
+ * like MSVC will complain about un-initialized variables if OBJECT
+ * hasn't already been initialized. To prevent such warnings, INIT_CONTAINER()
+ * can be used as a wrapper around ASSIGN_CONTAINER. */
+#define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \
+ ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER))
+
/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
* (void *). This is to suppress the alignment warning issued by clang. */
#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
#define PRIXSIZE "zX"
#endif
+#ifndef _WIN32
+typedef uint32_t HANDLE;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
const char *get_program_version(void);
void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
-void out_of_memory(void) NO_RETURN;
+NO_RETURN void out_of_memory(void);
void *xmalloc(size_t) MALLOC_LIKE;
void *xcalloc(size_t, size_t) MALLOC_LIKE;
void *xzalloc(size_t) MALLOC_LIKE;
void ovs_strlcpy(char *dst, const char *src, size_t size);
void ovs_strzcpy(char *dst, const char *src, size_t size);
-void ovs_abort(int err_no, const char *format, ...)
- PRINTF_FORMAT(2, 3) NO_RETURN;
-void ovs_abort_valist(int err_no, const char *format, va_list)
- PRINTF_FORMAT(2, 0) NO_RETURN;
-void ovs_fatal(int err_no, const char *format, ...)
- PRINTF_FORMAT(2, 3) NO_RETURN;
-void ovs_fatal_valist(int err_no, const char *format, va_list)
- PRINTF_FORMAT(2, 0) NO_RETURN;
+NO_RETURN void ovs_abort(int err_no, const char *format, ...)
+ PRINTF_FORMAT(2, 3);
+NO_RETURN void ovs_abort_valist(int err_no, const char *format, va_list)
+ PRINTF_FORMAT(2, 0);
+NO_RETURN void ovs_fatal(int err_no, const char *format, ...)
+ PRINTF_FORMAT(2, 3);
+NO_RETURN void ovs_fatal_valist(int err_no, const char *format, va_list)
+ PRINTF_FORMAT(2, 0);
void ovs_error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
void ovs_error_valist(int err_no, const char *format, va_list)
PRINTF_FORMAT(2, 0);
bool str_to_int(const char *, int base, int *);
bool str_to_long(const char *, int base, long *);
bool str_to_llong(const char *, int base, long long *);
-
-static inline bool
-str_to_uint(const char *s, int base, unsigned int *u)
-{
- return str_to_int(s, base, (int *) u);
-}
-
-static inline bool
-str_to_ulong(const char *s, int base, unsigned long *ul)
-{
- return str_to_long(s, base, (long *) ul);
-}
-
-static inline bool
-str_to_ullong(const char *s, int base, unsigned long long *ull)
-{
- return str_to_llong(s, base, (long long *) ull);
-}
+bool str_to_uint(const char *, int base, unsigned int *);
bool ovs_scan(const char *s, const char *format, ...) SCANF_FORMAT(2, 3);
const char *english_list_delimiter(size_t index, size_t total);
char *get_cwd(void);
+#ifndef _WIN32
char *dir_name(const char *file_name);
char *base_name(const char *file_name);
+#endif
char *abs_file_name(const char *dir, const char *file_name);
char *follow_symlinks(const char *filename);
return x ? log_2_floor(x) : 32;
}
\f
-bool is_all_zeros(const uint8_t *, size_t);
-bool is_all_ones(const uint8_t *, size_t);
+bool is_all_zeros(const void *, size_t);
+bool is_all_ones(const void *, size_t);
void bitwise_copy(const void *src, unsigned int src_len, unsigned int src_ofs,
void *dst, unsigned int dst_len, unsigned int dst_ofs,
unsigned int n_bits);
unsigned int src_ofs, unsigned int n_bits);
void xsleep(unsigned int seconds);
+
#ifdef _WIN32
\f
char *ovs_format_message(int error);