Split a few functions out into new file util.c.
9 razor_create_dir(const char *root, const char *path)
11 char buffer[PATH_MAX], *p;
12 const char *slash, *next;
15 /* Create all sub-directories in dir and then create name. We
16 * know root exists and is a dir, root does not end in a '/',
17 * and path has a leading '/'. */
20 p = buffer + strlen(buffer);
22 for (slash = path; slash[1] != '\0'; slash = next) {
23 next = strchr(slash + 1, '/');
24 memcpy(p, slash, next - slash);
28 if (stat(buffer, &buf) == 0) {
29 if (!S_ISDIR(buf.st_mode)) {
31 "%s exists but is not a directory\n",
35 } else if (mkdir(buffer, 0777) < 0) {
36 fprintf(stderr, "failed to make directory %s: %m\n",
41 /* FIXME: What to do about permissions for dirs we
42 * have to create but are not in the cpio archive? */
49 razor_write(int fd, const void *data, size_t size)
53 const unsigned char *p;
58 written = write(fd, p, rest);
60 fprintf(stderr, "write error: %m\n");