Change the install iterator API to what we want.
2 * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
3 * Copyright (C) 2008 Red Hat, Inc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "razor-internal.h"
31 razor_create_dir(const char *root, const char *path)
33 char buffer[PATH_MAX], *p;
34 const char *slash, *next;
37 /* Create all sub-directories in dir. We know root exists and
38 * is a dir, root does not end in a '/', and path has a
42 p = buffer + strlen(buffer);
44 for (slash = path; *slash != '\0'; slash = next) {
45 next = strchr(slash + 1, '/');
49 memcpy(p, slash, next - slash);
53 if (stat(buffer, &buf) == 0) {
54 if (!S_ISDIR(buf.st_mode)) {
56 "%s exists but is not a directory\n",
60 } else if (mkdir(buffer, 0777) < 0) {
61 fprintf(stderr, "failed to make directory %s: %m\n",
66 /* FIXME: What to do about permissions for dirs we
67 * have to create but are not in the cpio archive? */
74 razor_write(int fd, const void *data, size_t size)
78 const unsigned char *p;
83 written = write(fd, p, rest);
85 fprintf(stderr, "write error: %m\n");
95 struct qsort_context {
97 razor_compare_with_data_func_t compare;
102 qsort_swap(void *p1, void *p2, size_t size)
106 memcpy(buffer, p1, size);
107 memcpy(p1, p2, size);
108 memcpy(p2, buffer, size);
112 __qsort_with_data(void *base, size_t nelem, uint32_t *map,
113 struct qsort_context *ctx)
115 void *p, *start, *end, *pivot;
116 uint32_t *mp, *mstart, *mend, tmp;
117 int left, right, result;
118 size_t size = ctx->size;
122 end = base + nelem * size;
126 pivot = base + (random() % nelem) * size;
129 result = ctx->compare(p, pivot, ctx->data);
131 qsort_swap(p, start, size);
141 } else if (result == 0) {
147 qsort_swap(p, end, size);
156 left = (start - base) / size;
157 right = (base + nelem * size - end) / size;
159 __qsort_with_data(base, left, map, ctx);
161 __qsort_with_data(end, right, mend, ctx);
165 razor_qsort_with_data(void *base, size_t nelem, size_t size,
166 razor_compare_with_data_func_t compare, void *data)
168 struct qsort_context ctx;
176 ctx.compare = compare;
179 map = malloc(nelem * sizeof (uint32_t));
180 for (i = 0; i < nelem; i++)
183 __qsort_with_data(base, nelem, map, &ctx);