/* * Copyright (C) 2011-2012 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #ifdef MSWIN_API #include #endif #include #include #include "razor.h" #include "razor-internal.h" RAZOR_EXPORT const char * razor_error_get_msg(struct razor_error *error) { if (!error->msg) { if (error->path) error->msg = razor_concat(error->path, ": ", error->str, NULL); else error->msg = strdup(error->str); } return error->msg; } #ifdef MSWIN_API struct razor_error * razor_error_new_mswin(const wchar_t *path, DWORD err) { struct razor_error *error; wchar_t *buf; error = zalloc(sizeof *error); if (path) error->path = razor_utf16_to_utf8(path, -1); FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPWSTR)&buf, 0, NULL); error->str = razor_utf16_to_utf8(buf, -1); LocalFree(buf); return error; } struct razor_error * razor_error_new_str2(const wchar_t *path, const char *str) { struct razor_error *error; error = zalloc(sizeof *error); if (path) error->path = razor_utf16_to_utf8(path, -1); error->str = strdup(str); return error; } #endif /* MSWIN_API */ RAZOR_EXPORT struct razor_error * razor_error_new_str(const char *path, const char *str) { struct razor_error *error; error = zalloc(sizeof *error); if (path) error->path = strdup(path); error->str = strdup(str); return error; } RAZOR_EXPORT void razor_error_free(struct razor_error *error) { free(error->path); free(error->str); free(error->msg); free(error); }