TEST(symlinks_in_paths_are_not_resolved, IF(not_windows)) { char canonic_path[PATH_MAX + 1]; char buf[PATH_MAX + 1]; assert_success(os_mkdir(SANDBOX_PATH "/dir1", 0700)); assert_success(os_mkdir(SANDBOX_PATH "/dir1/dir2", 0700)); /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 { char src[PATH_MAX + 1], dst[PATH_MAX + 1]; make_abs_path(src, sizeof(src), SANDBOX_PATH, "dir1/dir2", saved_cwd); make_abs_path(dst, sizeof(dst), SANDBOX_PATH, "dir-link", saved_cwd); assert_success(symlink(src, dst)); } #endif assert_success(chdir(SANDBOX_PATH "/dir-link")); make_abs_path(buf, sizeof(buf), SANDBOX_PATH, "dir-link", saved_cwd); to_canonic_path(buf, "/fake-root", lwin.curr_dir, sizeof(lwin.curr_dir)); to_canonic_path(sandbox, "/fake-root", canonic_path, sizeof(canonic_path)); /* :mkdir */ (void)exec_commands("mkdir ../dir", &lwin, CIT_COMMAND); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(rmdir(SANDBOX_PATH "/dir")); /* :clone file name. */ create_file(SANDBOX_PATH "/dir-link/file"); populate_dir_list(&lwin, 1); (void)exec_commands("clone ../file-clone", &lwin, CIT_COMMAND); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(remove(SANDBOX_PATH "/file-clone")); assert_success(remove(SANDBOX_PATH "/dir-link/file")); /* :colorscheme */ make_abs_path(cfg.colors_dir, sizeof(cfg.colors_dir), TEST_DATA_PATH, "scripts/", saved_cwd); snprintf(buf, sizeof(buf), "colorscheme set-env %s/../dir-link/..", sandbox); assert_success(exec_commands(buf, &lwin, CIT_COMMAND)); cs_load_defaults(); /* :cd */ assert_success(exec_commands("cd ../dir-link/..", &lwin, CIT_COMMAND)); assert_string_equal(canonic_path, lwin.curr_dir); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(remove(SANDBOX_PATH "/dir-link")); assert_success(rmdir(SANDBOX_PATH "/dir1/dir2")); assert_success(rmdir(SANDBOX_PATH "/dir1")); }
int iop_mkdir(io_args_t *const args) { const char *const path = args->arg1.path; const int create_parent = args->arg2.process_parents; const mode_t mode = args->arg3.mode; #ifndef _WIN32 enum { PATH_PREFIX_LEN = 0 }; #else enum { PATH_PREFIX_LEN = 2 }; #endif if(create_parent) { char *const partial_path = strdup(path); char *part = partial_path + PATH_PREFIX_LEN, *state = NULL; while((part = split_and_get(part, '/', &state)) != NULL) { if(is_dir(partial_path)) { continue; } /* Create intermediate directories with 0700 permissions. */ if(os_mkdir(partial_path, S_IRWXU) != 0) { (void)ioe_errlst_append(&args->result.errors, partial_path, errno, strerror(errno)); free(partial_path); return -1; } } #ifndef _WIN32 if(os_chmod(path, mode) != 0) { (void)ioe_errlst_append(&args->result.errors, partial_path, errno, strerror(errno)); free(partial_path); return 1; } #endif free(partial_path); return 0; } if(os_mkdir(path, mode) != 0) { (void)ioe_errlst_append(&args->result.errors, path, errno, strerror(errno)); return 1; } return 0; }
update_info_t *update_info_create( const char *log_prefix, const char *user_agent, const char *update_url, const char *local_dir, const char *cache_dir, confirm_file_callback_t confirm_callback, void *param) { struct update_info *info; struct dstr dir = {0}; if (!log_prefix) log_prefix = ""; if (os_mkdir(cache_dir) < 0) { blog(LOG_WARNING, "%sCould not create cache directory %s", log_prefix, cache_dir); return NULL; } dstr_copy(&dir, cache_dir); if (dstr_end(&dir) != '/' && dstr_end(&dir) != '\\') dstr_cat_ch(&dir, '/'); dstr_cat(&dir, ".temp"); if (os_mkdir(dir.array) < 0) { blog(LOG_WARNING, "%sCould not create temp directory %s", log_prefix, cache_dir); dstr_free(&dir); return NULL; } info = bzalloc(sizeof(*info)); info->log_prefix = bstrdup(log_prefix); info->user_agent = bstrdup(user_agent); info->temp = dir.array; info->local = bstrdup(local_dir); info->cache = bstrdup(cache_dir); info->url = get_path(update_url, "package.json"); info->callback = confirm_callback; info->param = param; if (pthread_create(&info->thread, NULL, update_thread, info) == 0) info->thread_created = true; return info; }
TEST(reset_executable_bits_from_files_only, IF(not_osx)) { FILE *f; int perms[13] = { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1 }; int adv_perms[3] = { 1, 1, 1 }; int origin_perms[13] = { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 }; assert_success(os_mkdir(SANDBOX_PATH "/dir", 0777)); assert_non_null(f = fopen(SANDBOX_PATH "/dir/file", "w")); fclose(f); assert_success(chmod(SANDBOX_PATH "/dir/file", 0777)); if(get_perms(SANDBOX_PATH "/dir") != 0777 || get_perms(SANDBOX_PATH "/dir/file") != 0777) { assert_success(unlink(SANDBOX_PATH "/dir/file")); assert_success(rmdir(SANDBOX_PATH "/dir")); return; } strcpy(lwin.curr_dir, SANDBOX_PATH); alloc_file_list(&lwin, "dir"); set_perm_string(&lwin, perms, origin_perms, adv_perms); free_file_list(&lwin); assert_int_equal(perms_to_mode(perms), get_perms(SANDBOX_PATH "/dir/file")); assert_int_equal(0777, get_perms(SANDBOX_PATH "/dir")); assert_success(unlink(SANDBOX_PATH "/dir/file")); assert_success(rmdir(SANDBOX_PATH "/dir")); }
TEST(symlinks_are_not_resolved_in_tree_preview, IF(not_windows)) { int nlines; FILE *fp; char **lines; assert_success(os_mkdir(SANDBOX_PATH "/dir", 0777)); /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 assert_success(symlink(".", SANDBOX_PATH "/dir/link")); #endif fp = qv_view_dir(SANDBOX_PATH "/dir"); lines = read_file_lines(fp, &nlines); assert_int_equal(4, nlines); assert_string_equal("dir/", lines[0]); assert_string_equal("`-- link/ -> .", lines[1]); assert_string_equal("", lines[2]); assert_string_equal("1 directory, 0 files", lines[3]); free_string_array(lines, nlines); fclose(fp); assert_success(unlink(SANDBOX_PATH "/dir/link")); assert_success(rmdir(SANDBOX_PATH "/dir")); }
// Create the parent dir of the file. // TODO Does this work if the parent parent dir does not exist? static int createParentDirs(const std::string &filename) { int err = 1; // TODO This function may not work correctly or be portable. // Perhaps should only search for '\\' on win32, '/' otherwise size_t pos = filename.find_last_of("\\/"); // Return if no separator is found, or if it is the first // character, e.g. /home if (pos == std::string::npos || pos == 0) return 0; const std::string &path = filename.substr(0, pos); if ((err = createParentDirs(path))) { // There was an error creating the parent path. return err; } // See if the directory already exists DIR *d = opendir(path.c_str()); if (!d) { // Make dir as it doesn't exist err = os_mkdir(path); } else{ closedir(d); err = 0; } return err; }
int mkdir_recursive(const char *path, int mode) { char *path_copy; char *path_next; int err = 0; size_t path_len = strlen(path); path_copy = malloc(path_len + 1); if(!path_copy) { return -1; } if(strlcpy(path_copy, path, path_len + 1) >= path_len + 1) { // this should never happen err = -1; goto fail; } path_next = path_copy; if(*path_next == '/') path_next++; while((path_next = strchr(path_next, '/'))) { char save_chr = *path_next; // save the next path char *path_next = 0; // terminate if(!os_is_directory(path_copy)) { err = os_mkdir(path_copy, mode); if(err != 0) goto fail; } *path_next = save_chr; path_next++; } if(!os_is_directory(path_copy)) { err = os_mkdir(path_copy, mode); if(err != 0) goto fail; } fail: free(path_copy); return err; }
int mkdir(const char *dirname, mode_t mode) { int rc; if ( os_mkdir( dirname, mode, &rc ) == NOTIMPLEMENTED ) os_freakout(); return rc; }
static int recursive_mkdir(char *path) { char *last_slash; int ret; ret = os_mkdir(path); if (ret != MKDIR_ERROR) return ret; last_slash = strrchr(path, '/'); if (!last_slash) return MKDIR_ERROR; *last_slash = 0; ret = recursive_mkdir(path); *last_slash = '/'; if (ret == MKDIR_ERROR) return MKDIR_ERROR; ret = os_mkdir(path); return ret; }
// NOTE: // filename = NULL to read/write global config ( ~/.MyTunet ) CHAR *setting_load_file(CHAR *filename) { CHAR *tmpbuf; CHAR globalconfigfile[1024]; CHAR *p; FILE *fp; INT filesize; CHAR *comment = "# WARNING: This file is created by MyTunet. DO NOT edit this file!\r\n"; if(!filename) { memset(globalconfigfile, 0, sizeof(globalconfigfile)); strncpy(globalconfigfile, os_get_home_dir(), sizeof(globalconfigfile)); strncat(globalconfigfile, "/.MyTunet/MyTunet", sizeof(globalconfigfile)); filename = globalconfigfile; } fp = fopen(filename, "rb+"); if(!fp) { fp = fopen(filename, "wb+"); if(!fp) { os_mkdir(globalconfigfile, TRUE); fp = fopen(filename, "wb+"); } if(fp) fclose(fp); tmpbuf = os_new(CHAR, strlen(comment) + 1); strcpy(tmpbuf, comment); return tmpbuf; } fseek(fp, 0, SEEK_END); filesize = ftell(fp); fseek(fp, 0, SEEK_SET); tmpbuf = os_new(CHAR, filesize + 1); fread(tmpbuf, filesize, 1, fp); fclose(fp); tmpbuf[filesize] = 0; while( (p=strchr(tmpbuf, '\r')) != NULL) *p ='\n'; return tmpbuf; }
SETUP() { char cwd[PATH_MAX]; assert_success(chdir(SANDBOX_PATH)); assert_true(get_cwd(cwd, sizeof(cwd)) == cwd); copy_str(view->curr_dir, sizeof(view->curr_dir), cwd); assert_success(os_mkdir("0", 0000)); assert_success(os_mkdir("1", 0000)); assert_success(os_mkdir("2", 0000)); assert_success(os_mkdir("3", 0000)); filter_init(&view->local_filter.filter, 1); filter_init(&view->manual_filter, 1); filter_init(&view->auto_filter, 1); view->sort[0] = SK_BY_NAME; memset(&view->sort[1], SK_NONE, sizeof(view->sort) - 1); view->dir_entry = NULL; view->list_rows = 0; populate_dir_list(view, 0); }
void io_com_dump(MPI_Comm comm, const Coords *coords, const char *name, long id, int n, const int *ii, const float3 *rr) { char fname[FILENAME_MAX] = {0}, *data; long nchar = 0; EMALLOC(MAX_CHAR_PER_LINE * n, &data); if (m::is_master(comm)) UC(os_mkdir(BASE)); gen_fname(name, id, fname); UC(nchar = swrite(coords, n, ii, rr, /**/ data)); write_mpi(comm, fname, nchar, data); EFREE(data); }
int file_open(LOG_CTX* ctx, const char* url) { const char* v; v = strstr(url, "@"); if(v) { char mode[20]; memcpy(&mode, url, v-url); mode[v-url] = '\0'; if(strcmp(mode, "single")==0) { ctx->file->mode = FILE_MODE_SINGLE; } else if(strcmp(mode, "once")==0) { ctx->file->mode = FILE_MODE_ONCE; } else if(strcmp(mode, "day")==0) { ctx->file->mode = FILE_MODE_EVERYDAY; } else if(strcmp(mode, "week")==0) { ctx->file->mode = FILE_MODE_EVERYWEEK; } else if(strcmp(mode, "mouth")==0) { ctx->file->mode = FILE_MODE_EVERYMOUTH; } else { return ERR_INVALID_PARAMETER; } url = v+1; } else { ctx->file->mode = FILE_MODE_SINGLE; } v = strrchr(url, '/'); if(v==NULL) v = strrchr(url, '\\'); if(v==NULL) v = url; else v++; strcpy(ctx->file->name, v); memset(ctx->file->path, 0, sizeof(ctx->file->path)); memcpy(ctx->file->path, url, v-url); if(!os_isdir(ctx->file->path) && os_mkdir(ctx->file->path)!=0) return ERR_UNKNOWN; ctx->file->mode = FILE_MODE_SINGLE; ctx->file->fp = file_create(ctx->file); if(ctx->file->fp==NULL) return ERR_FDOPEN; return ERR_NOERROR; }
// NOTE: // filename = NULL to read/write global config ( ~/.MyTunet ) VOID setting_save_file(CHAR *filename, CHAR *buf) { CHAR *p; FILE *fp; CHAR globalconfigfile[1024]; if(!filename) { memset(globalconfigfile, 0, sizeof(globalconfigfile)); strncpy(globalconfigfile, os_get_home_dir(), sizeof(globalconfigfile)); strncat(globalconfigfile, "/.MyTunet/MyTunet", sizeof(globalconfigfile)); filename = globalconfigfile; } p = buf; while( (p=strstr(buf,"\n\n")) != NULL) { if(*(p-1) != '\r') *p = '\r'; else *(p+1) = '\r'; } p = buf + strlen(buf) - 1; if(p) { while((*p == '\r' || *p =='\n') && (p != buf)) p--; p++; if(*p) p++; if(*p) p++; *p = 0; } if( (fp = fopen(filename, "wb+")) == NULL ) { os_mkdir(filename, TRUE); if( (fp = fopen(filename, "wb+")) == NULL ) return; } fwrite(buf, strlen(buf), 1, fp); fclose(fp); }
/* Windows has various limitations on characters used in file names. */ TEST(tilde_is_expanded_after_negation, IF(not_windows)) { char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/~", sandbox); assert_success(exec_commands("let $a = 'x'", &lwin, CIT_COMMAND)); assert_success(os_mkdir(path, 0700)); assert_success(exec_commands("auto DirEnter !~ let $a = 1", &lwin, CIT_COMMAND)); assert_string_equal("x", env_get("a")); assert_true(change_directory(curr_view, path) >= 0); assert_string_equal("1", env_get("a")); assert_success(rmdir(path)); }
TEST(chase_links_causes_link_to_be_resolved, IF(not_windows)) { assert_success(os_mkdir("dir", 0700)); /* symlink() is not available on Windows, but other code is fine. */ #ifndef _WIN32 assert_success(symlink("dir", "dir-link")); #endif assert_non_null(get_cwd(curr_view->curr_dir, sizeof(curr_view->curr_dir))); assert_true(change_directory(curr_view, "dir-link") >= 0); assert_string_equal("dir", get_last_path_component(curr_view->curr_dir)); /* Go out of the directory so that we can remove it. */ assert_true(change_directory(curr_view, "..") >= 0); assert_success(rmdir("dir")); assert_success(remove("dir-link")); }
TEST(chase_links_is_not_affected_by_chdir, IF(not_windows)) { char pwd[PATH_MAX]; assert_success(os_mkdir("dir", 0700)); /* symlink() is not available on Windows, but other code is fine. */ #ifndef _WIN32 assert_success(symlink("dir", "dir-link")); #endif assert_non_null(get_cwd(pwd, sizeof(pwd))); strcpy(curr_view->curr_dir, pwd); assert_true(change_directory(curr_view, "dir-link") >= 0); assert_success(chdir("..")); assert_true(change_directory(curr_view, "..") >= 0); assert_true(paths_are_equal(curr_view->curr_dir, pwd)); assert_success(rmdir("dir")); assert_success(remove("dir-link")); }
void paths_init(void) { #ifdef HAVE_SPECIAL_DIRS /* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */ #if (CONFIG_PLATFORM & PLATFORM_ANDROID) os_mkdir("/sdcard/rockbox" __MKDIR_MODE_ARG); os_mkdir("/sdcard/rockbox/rocks.data" __MKDIR_MODE_ARG); os_mkdir("/sdcard/rockbox/eqs" __MKDIR_MODE_ARG); #else char config_dir[MAX_PATH]; const char *home = getenv("RBROOT"); if (!home) { home = getenv("HOME"); } if (!home) { logf("HOME environment var not set. Can't write config"); return; } rbhome = home; snprintf(config_dir, sizeof(config_dir), "%s/.config", home); os_mkdir(config_dir __MKDIR_MODE_ARG); snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org", home); os_mkdir(config_dir __MKDIR_MODE_ARG); /* Plugin data directory */ snprintf(config_dir, sizeof(config_dir), "%s/.config/rockbox.org/rocks.data", home); os_mkdir(config_dir __MKDIR_MODE_ARG); #endif #endif /* HAVE_SPECIAL_DIRS */ #ifdef HAVE_MULTIDRIVE /* if this fails then alternate volumes will not work, but this function cannot return that fact */ rbhome_fildes = os_opendirfd(rbhome); if (rbhome_fildes >= 0) atexit(cleanup_rbhome); #endif /* HAVE_MULTIDRIVE */ }
bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text, const char *init_text) { std::string newName; std::string newDir; ConfigFile config; if (!GetProfileName(this, newName, newDir, title, text, init_text)) return false; std::string curDir = config_get_string(App()->GlobalConfig(), "Basic", "ProfileDir"); char newPath[512]; int ret = GetConfigPath(newPath, 512, "obs-studio/basic/profiles/"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return false; } strcat(newPath, newDir.c_str()); if (os_mkdir(newPath) < 0) { blog(LOG_WARNING, "Failed to create profile directory '%s'", newDir.c_str()); return false; } if (!create_new) CopyProfile(curDir.c_str(), newPath); strcat(newPath, "/basic.ini"); if (config.Open(newPath, CONFIG_OPEN_ALWAYS) != 0) { blog(LOG_ERROR, "Failed to open new config file '%s'", newDir.c_str()); return false; } config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName.c_str()); config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir.c_str()); config_set_string(config, "General", "Name", newName.c_str()); config.SaveSafe("tmp"); config.Swap(basicConfig); InitBasicConfigDefaults(); RefreshProfiles(); if (create_new) ResetProfileData(); blog(LOG_INFO, "Created profile '%s' (%s, %s)", newName.c_str(), create_new ? "clean" : "duplicate", newDir.c_str()); blog(LOG_INFO, "------------------------------------------------"); config_save_safe(App()->GlobalConfig(), "tmp", nullptr); UpdateTitleBar(); return true; }
/* * Create a local directory */ void CVmNetFile::mkdir_local(VMG_ int create_parents) { /* try creating the directory */ if (!os_mkdir(lclfname, create_parents)) err_throw(VMERR_CREATE_FILE); }
static int idl_createDir ( os_char* fname) { char *pathName; os_result statRes; struct os_stat statbuf; char* outdir; os_char* stackScope; os_char* token; const os_char* osSep; /* to allow nested modules which may potentially lead to very long paths, * pathName is not allocated fixed-size on stack * but dynamically on heap */ pathName = os_malloc(1); pathName[0] = '\0'; outdir = idl_dirOutCur(); if(outdir){ pathName = os_realloc(pathName, strlen(outdir) + strlen(os_fileSep()) + 1); if (pathName == NULL) { printf("Memory allocation failure when creating idl directory\n"); return 0; } os_sprintf(pathName, "%s%s", outdir, os_fileSep()); } /* make sure that we replace the os file seperator with a simple character * like '/', this will allow us to parse easier later. */ osSep = os_fileSep(); stackScope = idl_genJavaHelperSubstitute(fname, osSep, "/", NULL); if(stackScope[0] != '\0'){ /* strlen(stackScope) > 0 */ do { token = strchr(stackScope, '/'); /* make sure this is not the last part of the file name, for example * for the file name org/opensplice/foo.java we only want to create * directories for org and opensplice, the foo.java part is not a * directory. So we can simply state if no '/' char can be * found then we must be at the end part of the file name! */ if(token) { *token = '\0'; token++; /* reallocate pathName to include stackScope */ pathName = os_realloc(pathName, strlen(pathName) + strlen(stackScope) + 1); if (pathName == NULL) { printf("Memory allocation failure when trying to create idl directory %s, \ probably the path has grown too long\n", stackScope); return 0; } os_strcat (pathName, stackScope); stackScope = token; statRes = os_stat (pathName, &statbuf); if (statRes == os_resultFail) { /* @todo */ /* Assume the file does not exist. On some platforms */ /* a check to see if errno == ENOENT would be more conclusive */ /* That fails on WIN32 however because stat is not fully */ /* compatible. Only an os_stat implementation can solve that. */ os_mkdir(pathName, 0777); statRes = os_stat(pathName, &statbuf); } else { if (!OS_ISDIR(statbuf.stat_mode)) { printf ("File %s already exists, but is not a directory\n", pathName); os_free(pathName); return 0; } } if (statRes == os_resultFail) { printf ("Error when creating directory %s\n", pathName); os_free(pathName); return 0; } /* reallocate pathName to include os_fileSep() */ pathName = os_realloc(pathName, strlen(pathName) + strlen(stackScope) + strlen(os_fileSep()) + 1); if (pathName == NULL) { printf("Memory allocation failure when trying to add the \ file separator to idl directory %s", stackScope); return 0; } os_strcat (pathName, os_fileSep()); } } while(token);
/* mount_point should be an array of at least PATH_MAX characters * Returns non-zero on error. */ static int fuse_mount(FileView *view, char file_full_path[], const char param[], const char program[], char mount_point[]) { /* TODO: refactor this function fuse_mount(). */ int mount_point_id; char buf[2*PATH_MAX]; char *escaped_filename; int foreground; char errors_file[PATH_MAX]; int status; int cancelled; escaped_filename = escape_filename(get_current_file_name(view), 0); mount_point_id = get_last_mount_point_id(fuse_mounts); do { snprintf(mount_point, PATH_MAX, "%s/%03d_%s", cfg.fuse_home, ++mount_point_id, get_current_file_name(view)); } while(path_exists(mount_point, DEREF)); if(os_mkdir(mount_point, S_IRWXU) != 0) { free(escaped_filename); show_error_msg("Unable to create FUSE mount directory", mount_point); return -1; } free(escaped_filename); /* Just before running the mount, I need to chdir out temporarily from any FUSE mounted paths, Otherwise the fuse-zip command fails with "fusermount: failed to open current directory: permission denied" (this happens when mounting JARs from mounted JARs) */ if(vifm_chdir(cfg.fuse_home) != 0) { show_error_msg("FUSE MOUNT ERROR", "Can't chdir() to FUSE home"); return -1; } format_mount_command(mount_point, file_full_path, param, program, sizeof(buf), buf, &foreground); status_bar_message("FUSE mounting selected file, please stand by.."); if(foreground) { def_prog_mode(); endwin(); } generate_tmp_file_name("vifm.errors", errors_file, sizeof(errors_file)); strcat(buf, " 2> "); strcat(buf, errors_file); LOG_INFO_MSG("FUSE mount command: `%s`", buf); status = background_and_wait_for_status(buf, !foreground, &cancelled); clean_status_bar(); /* Check child process exit status. */ if(!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS) { FILE *ef; if(!WIFEXITED(status)) { LOG_ERROR_MSG("FUSE mounter didn't exit!"); } else { LOG_ERROR_MSG("FUSE mount command exit status: %d", WEXITSTATUS(status)); } ef = os_fopen(errors_file, "r"); if(ef == NULL) { LOG_SERROR_MSG(errno, "Failed to open temporary stderr file: %s", errors_file); } show_errors_from_file(ef, "FUSE mounter error"); werase(status_bar); if(cancelled) { status_bar_message("FUSE mount cancelled"); curr_stats.save_msg = 1; } else { show_error_msg("FUSE MOUNT ERROR", file_full_path); } if(unlink(errors_file) != 0) { LOG_SERROR_MSG(errno, "Error file deletion failure: %d", errors_file); } /* Remove the directory we created for the mount. */ (void)rmdir(mount_point); (void)vifm_chdir(flist_get_dir(view)); return -1; } unlink(errors_file); status_bar_message("FUSE mount success"); register_mount(&fuse_mounts, file_full_path, mount_point, mount_point_id); return 0; }
static int os_createLogDir (const char *name) { int result; os_result status; char dirName[OS_PATH_MAX]; struct os_stat statBuf; unsigned long i; memset(dirName, 0, OS_PATH_MAX); result = 0; if(name) { result = 1; for(i=0; name[i] != '\0' && result; i++) { if((name[i] == OS_FILESEPCHAR) && (i != 0)) { status = os_stat(dirName, &statBuf); if (status != os_resultSuccess) { os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO); status = os_stat(dirName, &statBuf); } if (status != os_resultSuccess || !OS_ISDIR (statBuf.stat_mode)) { #ifdef WIN32 if((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'*/ } else { result = 0; } #else result = 0; #endif } } dirName[i] = name[i]; } if(result) { if(dirName[i-1] != OS_FILESEPCHAR) { status = os_stat(dirName, &statBuf); if (status != os_resultSuccess) { os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO); status = os_stat(dirName, &statBuf); } if (status != os_resultSuccess || !OS_ISDIR (statBuf.stat_mode)) { #ifdef WIN32 if((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'. Check if it exists...*/ dirName[2] = OS_FILESEPCHAR; status = os_stat(dirName, &statBuf); if(status == os_resultFail) { result = 0; } } else { result = 0; } #else result = 0; #endif } } } } else { result = 0; } /* os_access write access check fails for kernel mode vxworks 6.8 and 6.9 * even for writeable directories. */ #if !( defined (VXWORKS_68) || defined (VXWORKS_69) ) || !defined (_WRS_KERNEL) if(result) { status = os_access(name, 2); /*Check whether dir is writable*/ if(status != os_resultSuccess) { #ifdef WIN32 if((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'. Check if it exists...*/ dirName[2] = OS_FILESEPCHAR; status = os_stat(dirName, &statBuf); if(status == os_resultFail) { result = 0; } } else { result = 0; } #else result = 0; #endif } } #endif return result; }
void create_empty_dir(const char path[]) { os_mkdir(path, 0700); assert_true(is_dir(path)); }
os_int32 ut_dirOutNew( const os_char *name) { os_int32 result; os_result status; char dirName[OS_PATH_MAX]; struct os_stat statBuf; os_uint32 i; memset(dirName, 0, OS_PATH_MAX); if (name) { result = 1; for (i = 0; i < strlen(name) && result; i++) { if ((name[i] == OS_FILESEPCHAR) && (i != 0)) { status = os_stat(dirName, &statBuf); if (status != os_resultSuccess) { os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO); status = os_stat(dirName, &statBuf); } if (!OS_ISDIR (statBuf.stat_mode)) { #ifdef WIN32 if ((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'*/ } else { printf("'%s' is not a directory\n", dirName); result = 0; ut_outputdir = NULL; } #else printf("'%s' is not a directory\n", dirName); result = 0; ut_outputdir = NULL; #endif } } dirName[i] = name[i]; } if (result) { if (dirName[i-1] != OS_FILESEPCHAR) { status = os_stat(dirName, &statBuf); if (status != os_resultSuccess) { os_mkdir(dirName, S_IRWXU | S_IRWXG | S_IRWXO); status = os_stat(dirName, &statBuf); } ut_outputdir = os_strdup(name); if (!OS_ISDIR(statBuf.stat_mode)) { #ifdef WIN32 if ((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'. Check if it exists...*/ dirName[2] = OS_FILESEPCHAR; status = os_stat(dirName, &statBuf); if (status == os_resultFail) { printf("'%s' is not available", dirName); result = 0; ut_outputdir = NULL; } } else { printf("'%s' is not a directory.\n", ut_outputdir); result = 0; ut_outputdir = NULL; } #else printf("'%s' is not a directory\n", dirName); result = 0; ut_outputdir = NULL; #endif } } else { ut_outputdir = (os_char *)os_malloc(strlen(name)+1); snprintf(ut_outputdir, strlen(name), "%s", name); } } } else { result = 0; ut_outputdir = NULL; } if (result) { status = os_access(ut_outputdir, 2); /* Check whether dir is writable */ if (status != os_resultSuccess) { #ifdef WIN32 if ((strlen(dirName) == 2) && (dirName[1] == ':')) { /*This is a device like for instance: 'C:'. Check if it exists...*/ dirName[2] = OS_FILESEPCHAR; status = os_stat(dirName, &statBuf); if (status == os_resultFail) { printf("'%s' cannot be found", dirName); result = 0; ut_outputdir = NULL; } } else { printf("Specified output directory '%s' is not writable.\n", ut_outputdir); result = 0; ut_outputdir = NULL; } #else printf("Specified output directory '%s' is not writable.\n", ut_outputdir); result = 0; ut_outputdir = NULL; #endif } } return result; }