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)
46 razor_error_set_object(struct razor_error *error, const char *object)
54 error->object = strdup(object);
60 error->obj_str = NULL;
69 RAZOR_EXPORT const char *
70 razor_error_get_object(struct razor_error *error)
75 static const char *razor_error_get_obj_str(struct razor_error *error)
78 return error->obj_str;
81 error->obj_str = razor_concat(error->object, ": ",
83 return error->obj_str;
90 * razor_error_get_primary_text:
92 * Retrieves the basic information about an error. If a summary has been set
93 * then this will be returned. Otherwise the error string possibly prefixed
94 * by the object will be returned instead.
96 * Returns: Primary text of error.
98 RAZOR_EXPORT const char *
99 razor_error_get_primary_text(struct razor_error *error)
102 return error->summary;
104 return razor_error_get_obj_str(error);
108 * razor_error_get_secondary_text:
110 * Retrieves more detailed information about an error, if any. If a summary
111 * has been set the error string possibly prefixed by the object will be
112 * returned. Otherwise NULL will be returned.
114 * Returns: Secondary text of error or NULL.
116 RAZOR_EXPORT const char *
117 razor_error_get_secondary_text(struct razor_error *error)
122 return razor_error_get_obj_str(error);
125 RAZOR_EXPORT const char *
126 razor_error_get_msg(struct razor_error *error)
128 const char *primary, *secondary;
133 primary = razor_error_get_primary_text(error);
135 secondary = razor_error_get_secondary_text(error);
138 error->msg = razor_concat(primary, "\n", secondary, NULL);
146 razor_error_new_mswin(const wchar_t *object, DWORD err)
148 struct razor_error *error;
151 error = zalloc(sizeof *error);
153 error->domain = RAZOR_MSWIN_ERROR;
157 error->object = razor_utf16_to_utf8(object, -1);
160 case ERROR_TRANSACTIONAL_OPEN_NOT_ALLOWED:
162 * Attempting to include files in a transaction on a filesystem
163 * that doesn't support them (only NTFS?) produces this error
164 * for which the default text isn't very informative. Try and
165 * give more useful information.
167 error->str = strdup("Not allowed (perhaps the filesystem "
168 "doesn't support transactions)");
171 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|
172 FORMAT_MESSAGE_FROM_SYSTEM|
173 FORMAT_MESSAGE_IGNORE_INSERTS,
175 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
176 (LPWSTR)&buf, 0, NULL);
177 error->str = razor_utf16_to_utf8(buf, -1);
186 razor_error_new_str2(int domain, int code, const wchar_t *object,
189 struct razor_error *error;
191 error = zalloc(sizeof *error);
193 error->domain = domain;
197 error->object = razor_utf16_to_utf8(object, -1);
199 error->str = strdup(str);
203 #endif /* MSWIN_API */
205 RAZOR_EXPORT struct razor_error *
206 razor_error_new_str(int domain, int code, const char *object, const char *str)
208 struct razor_error *error;
210 error = zalloc(sizeof *error);
212 error->domain = domain;
216 error->object = strdup(object);
218 error->str = strdup(str);
223 RAZOR_EXPORT struct razor_error *
224 razor_error_dup(struct razor_error *src, const char *summary)
226 struct razor_error *error;
228 error = zalloc(sizeof *error);
230 error->domain = src->domain;
231 error->code = src->code;
234 error->summary = strdup(summary);
235 else if (src->summary)
236 error->summary = strdup(src->summary);
239 error->object = strdup(src->object);
242 error->str = strdup(src->str);
248 razor_error_free(struct razor_error *error)
252 free(error->obj_str);
253 free(error->summary);