/* * pmemcto_set_funcs -- allow overriding libpmemcto's call to malloc, etc. */ void pmemcto_set_funcs( void *(*malloc_func)(size_t size), void (*free_func)(void *ptr), void *(*realloc_func)(void *ptr, size_t size), char *(*strdup_func)(const char *s), void (*print_func)(const char *s)) { LOG(3, NULL); util_set_alloc_funcs(malloc_func, free_func, realloc_func, strdup_func); out_set_print_func(print_func); je_cto_pool_set_alloc_funcs(malloc_func, free_func); }
int main(int argc, char *argv[]) { START(argc, argv, "traces_custom_function"); if (argc != 2) FATAL("usage: %s [v|p]", argv[0]); out_set_print_func(print_custom_function); out_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); switch (argv[1][0]) { case 'p': { LOG(0, "Log level NONE"); LOG(1, "Log level ERROR"); LOG(2, "Log level WARNING"); LOG(3, "Log level INFO"); LOG(4, "Log level DEBUG"); } break; case 'v': out_set_vsnprintf_func(vsnprintf_custom_function); LOG(0, "no format"); LOG(0, "pointer: %p", (void *)0x12345678); LOG(0, "string: %s", "Hello world!"); LOG(0, "number: %u", 12345678); errno = EINVAL; LOG(0, "!error"); break; default: FATAL("usage: %s [v|p]", argv[0]); } /* Cleanup */ out_fini(); DONE(NULL); }