2 * Copyright (C) 2011-2012 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "razor-internal.h"
30 RAZOR_EXPORT const char *
31 razor_error_get_msg(struct razor_error *error)
35 error->msg = razor_concat(error->path, ": ", error->str,
38 error->msg = strdup(error->str);
46 razor_error_new_mswin(const wchar_t *path, DWORD err)
48 struct razor_error *error;
51 error = zalloc(sizeof *error);
54 error->path = razor_utf16_to_utf8(path, -1);
56 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|
57 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
58 NULL, err, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
59 (LPWSTR)&buf, 0, NULL);
60 error->str = razor_utf16_to_utf8(buf, -1);
67 razor_error_new_str2(const wchar_t *path, const char *str)
69 struct razor_error *error;
71 error = zalloc(sizeof *error);
74 error->path = razor_utf16_to_utf8(path, -1);
76 error->str = strdup(str);
80 #endif /* MSWIN_API */
82 RAZOR_EXPORT struct razor_error *
83 razor_error_new_str(const char *path, const char *str)
85 struct razor_error *error;
87 error = zalloc(sizeof *error);
90 error->path = strdup(path);
92 error->str = strdup(str);
98 razor_error_free(struct razor_error *error)