// open a given path, mounting partitions as necessary FILE* fopen_path(const char *path, const char *mode) { if (ensure_path_mounted(path) != 0) { LOGE("Can't mount %s\n", path); return NULL; } // When writing, try to create the containing directory, if necessary. // Use generous permissions, the system (init.rc) will reset them. if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1, sehandle); FILE *fp = fopen(path, mode); return fp; }
// open a file given in root:path format, mounting partitions as necessary FILE* fopen_root_path(const char *root_path, const char *mode) { if (ensure_root_path_mounted(root_path) != 0) { LOGE("Can't mount %s\n", root_path); return NULL; } char path[PATH_MAX] = ""; if (translate_root_path(root_path, path, sizeof(path)) == NULL) { LOGE("Bad path %s\n", root_path); return NULL; } // When writing, try to create the containing directory, if necessary. // Use generous permissions, the system (init.rc) will reset them. if (strchr("wa", mode[0])) dirCreateHierarchy(path, 0777, NULL, 1); FILE *fp = fopen(path, mode); // if (fp == NULL) LOGE("Can't open %s\n", path); return fp; }