Drop drive letter from path to razor root when RAZOR_ROOT set.
If the RAZOR_ROOT environment variable was set to eg., /root then on
Microsoft Windows we were trying to use paths such as /rootC:/Programs
which is obviously wrong. Instead we should drop the drive letter
giving paths of the form /root/Programs. Note that the drive letter is
_not_ migrated to C:/root/Programs: If a root of C:/root was desired
then RAZOR_ROOT would have been set to C:/root.
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 struct razor_error *
57 razor_atomic_get_error(struct razor_atomic *atomic)
62 RAZOR_EXPORT const char *
63 razor_atomic_get_error_msg(struct razor_atomic *atomic)
66 return razor_error_get_msg(atomic->error);
72 razor_atomic_abort(struct razor_atomic *atomic, const char *error_msg)
75 atomic->error = razor_error_new_str(NULL, error_msg);
79 razor_atomic_in_error_state(struct razor_atomic *atomic)
81 return atomic->error && !atomic->in_undo;
87 * Common code with atomic-none and atomic-emulate
90 #define RAZOR_ASCII_ISALPHA(c) \
91 ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z')
94 razor_valid_root_name(const char *name)
96 if (razor_allow_all_root_names()) {
98 return !strpbrk(name, "/\\");
100 return !strchr(name, '/');
105 return RAZOR_ASCII_ISALPHA(name[0]) && name[1] == ':' &&
108 return name[0] == '\0';
113 razor_atomic_write(struct razor_atomic *atomic, int fd, const void *data,
118 if (razor_atomic_in_error_state(atomic))
122 written = write(fd, data, size);
124 atomic->error = razor_error_new_str(NULL,
140 razor_atomic_sync(struct razor_atomic *atomic, int handle)
142 if (razor_atomic_in_error_state(atomic))
145 if (fsync(handle) < 0) {
146 atomic->error = razor_error_new_str(NULL, strerror(errno));
154 razor_atomic_close(struct razor_atomic *atomic, int fd)
156 if (razor_atomic_in_error_state(atomic))
160 atomic->error = razor_error_new_str(NULL, strerror(errno));
167 #endif /* !HAVE_WINDOWS_KTM */