static int mkdirs(char *name) { int ret; char *x = name + 1; uid_t uid = -1; gid_t gid = -1; unsigned int mode = 0775; uint64_t cap = 0; if(name[0] != '/') return -1; for(;;) { x = adb_dirstart(x); if(x == 0) return 0; *x = 0; if (is_on_system(name) || is_on_vendor(name)) { fs_config(name, 1, &uid, &gid, &mode, &cap); } ret = adb_mkdir(name, mode); if((ret < 0) && (errno != EEXIST)) { D("mkdir(\"%s\") -> %s\n", name, strerror(errno)); *x = '/'; return ret; } else if(ret == 0) { ret = chown(name, uid, gid); if (ret < 0) { *x = '/'; return ret; } selinux_android_restorecon(name, 0); } *x++ = '/'; } return 0; }
/* <hint> may be: * - A simple product name * e.g., "sooner" TODO: debug? sooner-debug, sooner:debug? * - A relative path from the CWD to the ANDROID_PRODUCT_OUT dir * e.g., "out/target/product/sooner" * - An absolute path to the PRODUCT_OUT dir * e.g., "/src/device/out/target/product/sooner" * * Given <hint>, try to construct an absolute path to the * ANDROID_PRODUCT_OUT dir. */ static const char *find_product_out_path(const char *hint) { static char path_buf[PATH_MAX]; if (hint == NULL || hint[0] == '\0') { return NULL; } /* If it's already absolute, don't bother doing any work. */ if (adb_is_absolute_host_path(hint)) { strcpy(path_buf, hint); return path_buf; } /* If there are any slashes in it, assume it's a relative path; * make it absolute. */ if (adb_dirstart(hint) != NULL) { if (getcwd(path_buf, sizeof(path_buf)) == NULL) { fprintf(stderr, "adb: Couldn't get CWD: %s\n", strerror(errno)); return NULL; } if (strlen(path_buf) + 1 + strlen(hint) >= sizeof(path_buf)) { fprintf(stderr, "adb: Couldn't assemble path\n"); return NULL; } strcat(path_buf, OS_PATH_SEPARATOR_STR); strcat(path_buf, hint); return path_buf; } /* It's a string without any slashes. Try to do something with it. * * Try to find the root of the build tree, and build a PRODUCT_OUT * path from there. */ char top_buf[PATH_MAX]; const char *top = find_top(top_buf); if (top == NULL) { fprintf(stderr, "adb: Couldn't find top of build tree\n"); return NULL; } //TODO: if we have a way to indicate debug, look in out/debug/target/... snprintf(path_buf, sizeof(path_buf), "%s" OS_PATH_SEPARATOR_STR "out" OS_PATH_SEPARATOR_STR "target" OS_PATH_SEPARATOR_STR "product" OS_PATH_SEPARATOR_STR "%s", top_buf, hint); if (access(path_buf, F_OK) < 0) { fprintf(stderr, "adb: Couldn't find a product dir " "based on \"-p %s\"; \"%s\" doesn't exist\n", hint, path_buf); return NULL; } return path_buf; }
static int mkdirs(const char *name) { int ret; char *x = (char *)name + 1; for(;;) { x = adb_dirstart(x); if(x == 0) return 0; *x = 0; ret = adb_mkdir(name, 0775); *x = OS_PATH_SEPARATOR; if((ret < 0) && (errno != EEXIST)) { return ret; } x++; } return 0; }
static int mkdirs(char *path) { int ret; char *x = path + 1; for(;;) { x = adb_dirstart(x); if(x == 0) return 0; *x = 0; ret = adb_mkdir(path, 0775); *x = OS_PATH_SEPARATOR; if((ret < 0) && (errno != EEXIST)) { return ret; } x++; } return 0; }
static int mkdirs(char *name) { int ret; char *x = name + 1; if(name[0] != '/') return -1; for(;;) { x = adb_dirstart(x); if(x == 0) return 0; *x = 0; ret = adb_mkdir(name, 0775); if((ret < 0) && (errno != EEXIST)) { D("mkdir(\"%s\") -> %s\n", name, strerror(errno)); *x = '/'; return ret; } *x++ = '/'; } return 0; }