;
}
+struct example_struct {
+ long a;
+ const char *b;
+ long c;
+};
+
+static void
+test_evutil_upcast(void *arg)
+{
+ struct example_struct es1;
+ const char **cp;
+ es1.a = 5;
+ es1.b = "Hello";
+ es1.c = -99;
+
+ tt_int_op(evutil_offsetof(struct example_struct, b), ==, sizeof(long));
+
+ cp = &es1.b;
+ tt_ptr_op(EVUTIL_UPCAST(cp, struct example_struct, b), ==, &es1);
+
+end:
+ ;
+
+}
struct testcase_t util_testcases[] = {
{ "ipv4_parse", regress_ipv4_parse, 0, NULL, NULL },
{ "evutil_casecmp", test_evutil_casecmp, 0, NULL, NULL },
{ "strlcpy", test_evutil_strlcpy, 0, NULL, NULL },
{ "log", test_evutil_log, TT_FORK, NULL, NULL },
+ { "upcast", test_evutil_upcast, 0, NULL, NULL },
END_OF_TESTCASES,
};
}
*/
#define EVUTIL_UPCAST(ptr, type, field) \
- ((type *)((char*)ptr) - evutil_offsetof(type, field))
+ ((type *)(((char*)(ptr)) - evutil_offsetof(type, field)))
int evutil_socket_connect(evutil_socket_t *fd_ptr, struct sockaddr *sa, int socklen);