Add an error object.
This is intended to dis-entangle the two roles that the atomic
object has evolved into so that atomic need only be used where
atomic actions are actually being undertaken.
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);
69 razor_error_new_str(const wchar_t *path, const char *str)
72 razor_error_new_str(const char *path, const char *str)
75 struct razor_error *error;
77 error = zalloc(sizeof *error);
81 error->path = razor_utf16_to_utf8(path, -1);
84 error->path = strdup(path);
87 error->str = strdup(str);
92 void razor_error_free(struct razor_error *error)