2 * Copyright (C) 2011-2012, 2014 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.
23 #ifndef ERROR_TRANSACTIONAL_OPEN_NOT_ALLOWED
24 #define ERROR_TRANSACTIONAL_OPEN_NOT_ALLOWED 6832L
31 #include "razor-internal.h"
34 razor_error_get_domain(struct razor_error *error)
40 razor_error_get_code(struct razor_error *error)
45 RAZOR_EXPORT const char *
46 razor_error_get_object(struct razor_error *error)
51 static const char *razor_error_get_obj_str(struct razor_error *error)
54 return error->obj_str;
57 error->obj_str = razor_concat(error->object, ": ",
59 return error->obj_str;
66 * razor_error_get_primary_text:
68 * Retrieves the basic information about an error. If a summary has been set
69 * then this will be returned. Otherwise the error string possibly prefixed
70 * by the object will be returned instead.
72 * Returns: Primary text of error.
74 RAZOR_EXPORT const char *
75 razor_error_get_primary_text(struct razor_error *error)
78 return error->summary;
80 return razor_error_get_obj_str(error);
84 * razor_error_get_secondary_text:
86 * Retrieves more detailed information about an error, if any. If a summary
87 * has been set the error string possibly prefixed by the object will be
88 * returned. Otherwise NULL will be returned.
90 * Returns: Secondary text of error or NULL.
92 RAZOR_EXPORT const char *
93 razor_error_get_secondary_text(struct razor_error *error)
98 return razor_error_get_obj_str(error);
101 RAZOR_EXPORT const char *
102 razor_error_get_msg(struct razor_error *error)
104 const char *primary, *secondary;
109 primary = razor_error_get_primary_text(error);
111 secondary = razor_error_get_secondary_text(error);
114 error->msg = razor_concat(primary, "\n", secondary, NULL);
122 razor_error_new_mswin(const wchar_t *object, DWORD err)
124 struct razor_error *error;
127 error = zalloc(sizeof *error);
129 error->domain = RAZOR_MSWIN_ERROR;
133 error->object = razor_utf16_to_utf8(object, -1);
136 case ERROR_TRANSACTIONAL_OPEN_NOT_ALLOWED:
138 * Attempting to include files in a transaction on a filesystem
139 * that doesn't support them (only NTFS?) produces this error
140 * for which the default text isn't very informative. Try and
141 * give more useful information.
143 error->str = strdup("Not allowed (perhaps the filesystem "
144 "doesn't support transactions)");
147 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|
148 FORMAT_MESSAGE_FROM_SYSTEM|
149 FORMAT_MESSAGE_IGNORE_INSERTS,
151 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
152 (LPWSTR)&buf, 0, NULL);
153 error->str = razor_utf16_to_utf8(buf, -1);
162 razor_error_new_str2(int domain, int code, const wchar_t *object,
165 struct razor_error *error;
167 error = zalloc(sizeof *error);
169 error->domain = domain;
173 error->object = razor_utf16_to_utf8(object, -1);
175 error->str = strdup(str);
179 #endif /* MSWIN_API */
181 RAZOR_EXPORT struct razor_error *
182 razor_error_new_str(int domain, int code, const char *object, const char *str)
184 struct razor_error *error;
186 error = zalloc(sizeof *error);
188 error->domain = domain;
192 error->object = strdup(object);
194 error->str = strdup(str);
199 RAZOR_EXPORT struct razor_error *
200 razor_error_dup(struct razor_error *src, const char *summary)
202 struct razor_error *error;
204 error = zalloc(sizeof *error);
206 error->domain = src->domain;
207 error->code = src->code;
210 error->summary = strdup(summary);
211 else if (src->summary)
212 error->summary = strdup(src->summary);
215 error->object = strdup(src->object);
218 error->str = strdup(src->str);
224 razor_error_free(struct razor_error *error)
228 free(error->obj_str);
229 free(error->summary);