2 * Copyright (C) 2011-2012, 2016 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.
30 #include "razor-internal.h"
36 static int allow_all_root_names = 0;
39 * Primarily intended for testing named roots under UNIX platforms.
42 razor_disable_root_name_checks(int disable)
44 allow_all_root_names = disable;
48 razor_allow_all_root_names(void)
50 return allow_all_root_names;
53 RAZOR_EXPORT struct razor_error *
54 razor_atomic_get_error(struct razor_atomic *atomic)
59 RAZOR_EXPORT const char *
60 razor_atomic_get_error_msg(struct razor_atomic *atomic)
63 return razor_error_get_msg(atomic->error);
69 razor_atomic_abort(struct razor_atomic *atomic, int domain, int code,
70 const char *error_msg)
73 atomic->error = razor_error_new_str(domain, code, NULL,
78 razor_atomic_propagate_error(struct razor_atomic *atomic,
79 struct razor_error *error, const char *summary)
83 atomic->error = error;
86 atomic->error = razor_error_dup(error, summary);
89 razor_error_free(error);
93 razor_atomic_in_error_state(struct razor_atomic *atomic)
95 return atomic->error && !atomic->in_undo;
101 * Common code with atomic-none and atomic-emulate
104 #define RAZOR_ASCII_ISALPHA(c) \
105 ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z')
108 razor_valid_root_name(const char *name)
110 if (razor_allow_all_root_names()) {
112 return !strpbrk(name, "/\\");
114 return !strchr(name, '/');
119 return RAZOR_ASCII_ISALPHA(name[0]) && name[1] == ':' &&
122 return name[0] == '\0';
127 razor_atomic_write(struct razor_atomic *atomic, int fd, const void *data,
132 if (razor_atomic_in_error_state(atomic))
136 written = write(fd, data, size);
138 atomic->error = razor_error_new_posix(NULL);
153 razor_atomic_sync(struct razor_atomic *atomic, int handle)
155 if (razor_atomic_in_error_state(atomic))
158 if (fsync(handle) < 0) {
159 atomic->error = razor_error_new_posix(NULL);
167 razor_atomic_close(struct razor_atomic *atomic, int fd)
169 if (razor_atomic_in_error_state(atomic))
173 atomic->error = razor_error_new_posix(NULL);
180 #endif /* !HAVE_WINDOWS_KTM */