/* wrappi * Copyright (C) 2011-2012 Red Hat Inc. * * This library 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 of the License, or (at your option) any later version. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include "wrappi.h" #include "internal.h" wrap_h * wrap_create (void) { struct wrap_h *w = calloc (1, sizeof *w); if (w == NULL) return NULL; return w; } void wrap_close (wrap_h *w) { free (w); } static void set_error_buf (struct wrap_internal_h *w, char *buf, int errnum, const char *func) { free (w->error); w->error = buf; w->errnum = errnum; /* 'func' is always statically allocated, since it comes from * C99 __func__, so this is safe. */ if (STRPREFIX (func, "impl_")) func += 5; else if (STRPREFIX (func, "wrap_")) func += 5; w->error_func = func; /* XXX This will be conditional on the user setting an error handler. */ fprintf (stderr, "wrappi: %s: %s\n", func, buf); } void wrap_int_set_error (struct wrap_internal_h *w, const char *func, const char *fs, ...) { va_list args; char *msg; int err; va_start (args, fs); err = vasprintf (&msg, fs, args); va_end (args); if (err < 0) return; set_error_buf (w, msg, 0, func); } void wrap_int_set_error_errno (struct wrap_internal_h *w, int errnum, const char *func, const char *fs, ...) { va_list args; char *msg; int err; va_start (args, fs); err = vasprintf (&msg, fs, args); va_end (args); if (err < 0) return; set_error_buf (w, msg, errnum, func); }