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.
26 #include <sys/types.h>
33 #include "razor-internal.h"
39 static int allow_all_root_names = 0;
42 * Primarily intended for testing named roots under UNIX platforms.
45 razor_disable_root_name_checks(int disable)
47 allow_all_root_names = disable;
51 razor_allow_all_root_names(void)
53 return allow_all_root_names;
56 RAZOR_EXPORT const char *
57 razor_atomic_get_error_msg(struct razor_atomic *atomic)
60 return razor_error_get_msg(atomic->error);
66 razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg)
69 atomic->error = razor_error_new_str(NULL, error_msg);
73 razor_atomic_in_error_state(struct razor_atomic *atomic)
75 return atomic->error && !atomic->in_undo;
81 * Common code with atomic-none and atomic-emulate
84 #define RAZOR_ASCII_ISALPHA(c) \
85 ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z')
88 razor_valid_root_name(const char *name)
90 if (razor_allow_all_root_names()) {
92 return !strpbrk(name, "/\\");
94 return !strchr(name, '/');
99 return RAZOR_ASCII_ISALPHA(name[0]) && name[1] == ':' &&
102 return name[0] == '\0';
107 razor_atomic_write(struct razor_atomic *atomic, int fd, const void *data,
112 if (razor_atomic_in_error_state(atomic))
116 written = write(fd, data, size);
118 atomic->error = razor_error_new_str(NULL,
134 razor_atomic_sync(struct razor_atomic *atomic, int handle)
136 if (razor_atomic_in_error_state(atomic))
139 if (fsync(handle) < 0) {
140 atomic->error = razor_error_new_str(NULL, strerror(errno));
148 razor_atomic_close(struct razor_atomic *atomic, int fd)
150 if (razor_atomic_in_error_state(atomic))
154 atomic->error = razor_error_new_str(NULL, strerror(errno));
161 #endif /* !HAVE_WINDOWS_KTM */