/// 需要移动到公共目录下,递归创建目录 static int RecurseCreateDirectory(const char *dir) { if( dir[0] == 0 ) return DDCE_ARGUMENT_ERROR; DDC_BOOL_RETURN( dir_exists(dir),DDCE_SUCCESS ); char dirFather[MAX_PATH*2]; strncpy(dirFather,dir,MAX_PATH*2); char *p = strrchr(dirFather,DDC_C_SLASH); if( p ) *p = 0; while( !dir_exists(dirFather) ) { int ret = RecurseCreateDirectory(dirFather); if( ret != 0 ) return ret; } //目录结尾不带"\\" if( dir[strlen(dir)-1] != DDC_C_SLASH ) return CreateDirectory(dir,NULL)==TRUE?0:DDCE_DISK_OP_ERROR; return 0; }
// // store a room in the persistent database void worldStorePersistentRoom(WORLD_DATA *world, const char *key, ROOM_DATA *room) { static char fname[MAX_BUFFER]; static char dir1[SMALL_BUFFER]; static char dir2[SMALL_BUFFER]; if(!*key) return; unsigned long hash1 = pearson_hash8_1(key) % WORLD_BINS; unsigned long hash2 = pearson_hash8_2(key) % WORLD_BINS; *fname = '\0'; *dir1 = '\0'; *dir2 = '\0'; // make sure our hash bins exist sprintf(dir1, "%s/persistent/%lu", worldGetPath(world), hash1); if(!dir_exists(dir1)) mkdir(dir1, S_IRWXU | S_IRWXG); // and the second one as well sprintf(dir2, "%s/persistent/%lu/%lu", worldGetPath(world), hash1, hash2); if(!dir_exists(dir2)) mkdir(dir2, S_IRWXU | S_IRWXG); // now, store the room sprintf(fname, "%s/persistent/%lu/%lu/%s", worldGetPath(world), hash1, hash2, key); STORAGE_SET *set = roomStore(room); storage_write(set, fname); storage_close(set); // log_string("stored persistent room :: %s", fname); }
static int rmkdir(char* path) { /* * strip off trailing components unless we can stat the directory, or we * have run out of components */ char* i = strrchr(path, '/'); if (path[0] == '\0' || dir_exists(path)) return 0; if (i != NULL) { *i = '\0'; rmkdir(path); *i = '/'; mkdir(path, 0777); } #ifdef WIN32 return 0; #else if (dir_exists(path)) return 0; else return -1; #endif }
static bool cgm_mount_cgroup(void *hdata, const char *root, int type) { if (dir_exists(CGMANAGER_LOWER_SOCK)) return cgm_bind_dir(root, CGMANAGER_LOWER_SOCK); if (dir_exists(CGMANAGER_UPPER_SOCK)) return cgm_bind_dir(root, CGMANAGER_UPPER_SOCK); // Host doesn't have cgmanager running? Then how did we get here? return false; }
bool Setup::createDirIfNeeded(const char *path, int mode) { if (!dir_exists(path)) { if (makedirs(path, mode) != 0 || !dir_exists(path)) { fprintf(stderr, "failed to create missing directory: %s\n", path); return false; } } return true; }
static int initialize_catalog(void) { if (!initialized) { bool default_dir = true; /* directory config is of the format: "dir: /path/to/dir" */ if (global_settings.playlist_catalog_dir[0] && strcmp(global_settings.playlist_catalog_dir, PLAYLIST_CATALOG_DEFAULT_DIR)) { strcpy(playlist_dir, global_settings.playlist_catalog_dir); default_dir = false; } /* fall back to default directory if no or invalid config */ if (default_dir) { strcpy(playlist_dir, PLAYLIST_CATALOG_DEFAULT_DIR); if (!dir_exists(playlist_dir)) mkdir(playlist_dir); } playlist_dir_length = strlen(playlist_dir); if (dir_exists(playlist_dir)) { playlist_dir_exists = true; memset(most_recent_playlist, 0, sizeof(most_recent_playlist)); initialized = true; } } if (!playlist_dir_exists) { if (mkdir(playlist_dir) < 0) { splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir); return -1; } else { playlist_dir_exists = true; memset(most_recent_playlist, 0, sizeof(most_recent_playlist)); initialized = true; } } return 0; }
CacheSession::CacheSession(ClientSession *session, const char *url, uint32_t file_ttl, uint32_t dir_ttl) : FilterSession(session) { m_dir_ttl = file_ttl; m_dir_ttl = dir_ttl; string tmp(url); make_hash64("md5", tmp, m_url_hash, true); tmp = url + string(":meta:") + get_client_id(); make_hash64("md5", tmp, m_meta_key, true); tmp = url + string(":data:") + get_client_id(); make_hash64("md5", tmp, m_data_key, true); m_base_dir = cacheBaseDir() + SEPSTR + m_url_hash; if (!dir_exists(m_base_dir.c_str()) && makedirs(m_base_dir.c_str()) < 0) { m_enable = false; _DEBUG("Disabling Cache Session: can't create"); } #if 0 else if (!can_write_dir(m_base_dir.c_str())) { m_enable = false; _DEBUG("Disabling Cache Session: can't write"); } #endif else { m_enable = true; _DEBUG("Enabling Cache Session"); } }
static bool cgm_bind_dir(const char *root, const char *dirname) { nih_local char *cgpath = NULL; /* /sys should have been mounted by now */ cgpath = NIH_MUST( nih_strdup(NULL, root) ); NIH_MUST( nih_strcat(&cgpath, NULL, "/sys/fs/cgroup") ); if (!dir_exists(cgpath)) { ERROR("%s does not exist", cgpath); return false; } /* mount a tmpfs there so we can create subdirs */ if (mount("cgroup", cgpath, "tmpfs", 0, "size=10000,mode=755")) { SYSERROR("Failed to mount tmpfs at %s", cgpath); return false; } NIH_MUST( nih_strcat(&cgpath, NULL, "/cgmanager") ); if (mkdir(cgpath, 0755) < 0) { SYSERROR("Failed to create %s", cgpath); return false; } if (mount(dirname, cgpath, "none", MS_BIND, 0)) { SYSERROR("Failed to bind mount %s to %s", dirname, cgpath); return false; } return true; }
/* * We may decide to make the socket path customizable. For now * just assume it is in /sys/fs/cgroup/ which has some special * consequences */ static bool setup_cgroup_dir(void) { int ret; if (!dir_exists(CGDIR)) { nih_debug(CGDIR " does not exist"); return false; } if (daemon_running()) { nih_error("%s: cgmanager is already running", __func__); return false; } if (file_exists(CGMANAGER_SOCK)) { if (unlink(CGMANAGER_SOCK) < 0) { nih_error("%s: failed to delete stale cgmanager socket", __func__); return false; } } /* Check that /sys/fs/cgroup is writeable, else mount a tmpfs */ unlink(CGPROBE); ret = creat(CGPROBE, O_RDWR); if (ret >= 0) { close(ret); unlink(CGPROBE); return mkdir_cgmanager_dir(); } ret = mount("cgroup", CGDIR, "tmpfs", 0, "size=10000"); if (ret) { nih_debug("Failed to mount tmpfs on %s: %s", CGDIR, strerror(errno)); return false; } nih_debug("Mounted tmpfs onto %s", CGDIR); return mkdir_cgmanager_dir(); }
void spray(int s, const struct sockaddr *cli, int cli_len, const char *file_path, __u16 padding, unsigned int fr) { char *filename = basename(file_path); char *encoded_file_path; int size; int num_blocks; size = asprintf(&encoded_file_path, "%s/%s", ENCODED_DIR, filename); if (size == -1) { fprintf(stderr, "asprintf: cannot allocate encoded file path\n"); return; } /* Check if a directory for that name exists. */ if (!dir_exists(encoded_file_path)) { fprintf(stderr, "invalid request; %s encoding does not exist\n", filename); return; } num_blocks = get_num_blocks(filename); if (num_blocks == -1) { fprintf(stderr, "get_num_blocks: cannot find number of blocks\n"); return; } send_data_files(s, cli, cli_len, filename, num_blocks, padding, fr); send_code_files(s, cli, cli_len, filename, num_blocks, padding, fr); }
static int recursive_remove(const char * const path) { if (NULL == path) { return 0; } int e = 0; if (dir_exists(path)) { FTSENT * ent; const char * const ptrs[] = { path, 0 }; const int fts_options = FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV; FTS * fts = fts_open((char * const *)ptrs, fts_options, NULL); while((ent = fts_read(fts)) && 0 == e) { switch(ent->fts_info) { case FTS_NS: case FTS_DNR: case FTS_ERR: fprintf(stderr, "%s: fts_read error: %s\n", ent->fts_accpath, strerror(ent->fts_errno)); e = ent->fts_errno; break; case FTS_D: case FTS_DC: case FTS_DOT: case FTS_NSOK: break; case FTS_DP: case FTS_F: case FTS_SL: case FTS_SLNONE: case FTS_DEFAULT: if (0 != remove(ent->fts_accpath)) { fprintf(stderr, "Unable to remove %s. %s\n", ent->fts_accpath, strerror(ent->fts_errno)); e = ent->fts_errno; } break; } } fts_close(fts); } return e; }
/*-------------------------------------------------------------------------*/ int make_dir(char *path) { int i; char tmp_path1[MAXPATH], tmp_path2[MAXPATH], length, mkdir_error; if (path[0] == '\0') { return -1; } strmcpy(tmp_path1, path, sizeof(tmp_path1)); cat_separator(tmp_path1); length = strlen(tmp_path1); strncpy(tmp_path2, tmp_path1, 3); i = 3; while (i < length) { if (tmp_path1[i] == '\\') { tmp_path2[i] = '\0'; if (!dir_exists(tmp_path2)) { mkdir_error = mkdir(tmp_path2); if (mkdir_error) { path[i] = '\0'; return mkdir_error; } } } tmp_path2[i] = tmp_path1[i]; i++; } return 0; }
int dispatch(const avector * vec, const long const * lows, const long const * highs, const int num_ranges, const double d, const long lo, const long hi, const char * destdir, const char * fprefix) { // group file names: destdir/fprefix_g<rid>_d_lo_hi #define BASENAME_LEN 40 char vecgroupname[FILENAME_MAX]; char * psuffix, *pslash; int rid, rcounter = 0; bool last_range = FALSE; assert( vec!=NULL ); assert( destdir!=NULL ); if ( ! dir_exists(destdir) ) { fprintf(stderr, "ERROR: directory does not exist: %s\n", destdir); return 0; } if ( vec->size<=0 ) return 0; /* prepare for the group names: */ strncpy(vecgroupname, destdir, FILENAME_MAX); vecgroupname[FILENAME_MAX-1] = 0; psuffix = vecgroupname + strlen(vecgroupname); assert( psuffix>vecgroupname ); assert( psuffix-vecgroupname < FILENAME_MAX-BASENAME_LEN ); // save space for actual names. pslash = strrchr(vecgroupname, '/'); if ( pslash==NULL || pslash+1!=psuffix ) *psuffix++ = '/'; *psuffix = 0; for ( rid=0; rid<num_ranges; rid++ ) { if ( vec->size < lows[rid] ) break; else if ( vec->size <= highs[rid] || highs[rid]<0 ) { // save the vector into this range: FILE * vgfile = NULL; snprintf(psuffix, BASENAME_LEN, "%s_g%d_%.8g_%ld_%ld", fprefix, rid+1, d, lo, hi); vgfile = fopen(vecgroupname, "a"); // NOTE: old group files are kept. if ( vgfile == NULL ) { fprintf(stderr, "Can't append to vector group file '%s'\n", vecgroupname); continue; } outputavector(vgfile, vec, 0); fclose(vgfile); rcounter++; if ( highs[rid]<0 ) { if ( last_range ) fprintf(stderr, "WARN: more than one -1 in the ranges; current rid = %d\n", rid+1); last_range = TRUE; } } else continue; } return rcounter; }
int run_uninstall_autoloader() { #ifdef ENABLE_LOG if (verbose) WriteToLog("[UNINSTALLER]"); #endif //Check if installed if(file_exists("/dev_flash/sys/internal/sys_init_osd_orig.self") != SUCCESS) { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd_orig.self not found\r\n"); #endif return FAILED; } //Enable dev_blind if(dir_exists("/dev_blind") != SUCCESS) { {lv2syscall8(SC_FS_MOUNT, (u64)(char*)"CELL_FS_IOS:BUILTIN_FLSH1", (u64)(char*)"CELL_FS_FAT", (u64)(char*)"/dev_blind", 0, 0, 0, 0, 0); } } //Restore original sys_init_osd.self if(file_exists(PATH_SYS_INI_OSD_ORIG) == SUCCESS) { if(file_exists(PATH_SYS_INI_OSD) == SUCCESS) { unlink_secure(PATH_SYS_INI_OSD); sysLv2FsRename(PATH_SYS_INI_OSD_ORIG, PATH_SYS_INI_OSD); //Remove payload char filename[128]; int fw_list[32] = { 0x355C,0x421C,0x430C,0x431C,0x440C,0x441C,0x446C,0x450C,0x453C,0x455C,0x460C,0x465C,0x466C,0x470C,0x475C,0x476C, 0x355D,0x421D,0x430D, 0x441D,0x446D,0x450D,0x453D,0x455D,0x460D,0x465D,0x466D,0x470D,0x475D,0x476D}; int i; for (i = 0; i < 32; i++) { if (fw_list[i] == 0) break; sprintf (filename, "/dev_blind/sys/internal/mpl_payload_%X.bin", fw_list[i]); if (file_exists(filename) == SUCCESS) unlink_secure(filename); sprintf (filename, "/dev_blind/sys/internal/mamba_%X.bin", fw_list[i]); if (file_exists(filename) == SUCCESS) unlink_secure(filename); } #ifdef ENABLE_LOG if (verbose) WriteToLog("Success: MAMBA/PRX Autoloader uninstalled\r\n"); #endif return SUCCESS; } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: sys_init_osd.self not found\r\n"); #endif return FAILED; } } else { #ifdef ENABLE_LOG if (verbose) WriteToLog("Error: /dev_blind not mounted\r\n"); #endif return FAILED; } }
bool DirectoryIterator::IsDirectory() { char dtmp[_MAX_PATH]; GetFullPath(dtmp); //this is needed on windows!!! FixPath(dtmp, false); return dir_exists(dtmp); }
END_TEST START_TEST (dir_exists_test) { int res; const char *path; res = dir_exists(NULL); fail_unless(res == FALSE, "Failed to handle null arguments"); path = "/"; res = dir_exists(path); fail_unless(res == TRUE, "Expected TRUE for path '%s', got FALSE", path); path = "./api-tests"; res = dir_exists(path); fail_unless(res == FALSE, "Expected FALSE for path '%s', got TRUE", path); }
void setup_proc() { if(!dir_exists("/proc")) mkdir("/proc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); int x = mount(NULL, "/proc", "proc", 0, NULL); if(x != 0) fatal(-1, true, "mount proc failed"); }
static rc_t populate_tool_ctx( tool_ctx_t * tool_ctx, const Args * args ) { rc_t rc = ArgsParamValue( args, 0, ( const void ** )&( tool_ctx -> accession_path ) ); if ( rc != 0 ) ErrMsg( "ArgsParamValue() -> %R", rc ); else { tool_ctx -> lookup_filename[ 0 ] = 0; tool_ctx -> index_filename[ 0 ] = 0; tool_ctx -> dflt_output[ 0 ] = 0; get_user_input( tool_ctx, args ); encforce_constrains( tool_ctx ); get_environment( tool_ctx ); rc = make_temp_dir( &tool_ctx -> temp_dir, tool_ctx -> requested_temp_path, tool_ctx -> dir ); } if ( rc == 0 ) rc = handle_accession( tool_ctx ); if ( rc == 0 ) rc = handle_lookup_path( tool_ctx ); if ( rc == 0 && tool_ctx -> output_dirname != NULL ) { if ( !dir_exists( tool_ctx -> dir, "%s", tool_ctx -> output_dirname ) ) rc = create_this_dir_2( tool_ctx -> dir, tool_ctx -> output_dirname, true ); } if ( rc == 0 ) { if ( tool_ctx -> output_filename == NULL ) { if ( tool_ctx -> output_dirname == NULL ) rc = make_output_filename_from_accession( tool_ctx ); else rc = make_output_filename_from_dir_and_accession( tool_ctx ); } else { if ( tool_ctx -> output_dirname == NULL ) rc = adjust_output_filename( tool_ctx ); else rc = adjust_output_filename_by_dir( tool_ctx ); } } if ( rc == 0 ) rc = Make_FastDump_Cleanup_Task ( &( tool_ctx -> cleanup_task ) ); /* cleanup_task.c */ if ( rc == 0 ) rc = Add_Directory_to_Cleanup_Task ( tool_ctx -> cleanup_task, get_temp_dir( tool_ctx -> temp_dir ) ); return rc; }
bool dir_create(const std::string& path, const std::string& outdir) { //std::string newpath = path + outdir; boost::filesystem::path p(path.c_str()); boost::filesystem::path f(outdir.c_str()); boost::filesystem::path r = p / f; std::string newpath = r.generic_string(); if (!dir_exists(newpath)) return fsnsp::create_directory(fsnsp::path(newpath.c_str())); return true; }
bool dir_create(const char *path) { const char *ptr; char buf[512]; /* If the directory already exists then we're done */ if (dir_exists(path)) return TRUE; #ifdef WINDOWS /* If we're on windows, we need to skip past the "C:" part. */ if (isalpha(path[0]) && path[1] == ':') path += 2; #endif /* Iterate through the path looking for path segements. At each step, * create the path segment if it doesn't already exist. */ for (ptr = path; *ptr; ptr++) { if (*ptr == PATH_SEPC) { /* Find the length of the parent path string */ size_t len = (size_t)(ptr - path); /* Skip the initial slash */ if (len == 0) continue; /* If this is a duplicate path separator, continue */ if (*(ptr - 1) == PATH_SEPC) continue; /* We can't handle really big filenames */ if (len - 1 > 512) return FALSE; /* Create the parent path string, plus null-padding */ my_strcpy(buf, path, len + 1); /* Skip if the parent exists */ if (dir_exists(buf)) continue; /* The parent doesn't exist, so create it or fail */ if (my_mkdir(buf, 0755) != 0) return FALSE; } } return my_mkdir(path, 0755) == 0 ? TRUE : FALSE; }
static int dir_create(const char* path) { if (!dir_exists(path)) if (mkdir(path, S_IRWXU) == -1) { perror("mkdir"); return -1; } return 0; }
bool dbExists (const string& dbname) { string dictfilename = dbname + DICT_TAG; string datadirname = dbname + DBDIR_TAG; if ( file_exists(dbname) || file_exists(dictfilename) || dir_exists(datadirname)) { cerr << "Found a previous database." << endl; return true; } else { return false; } }
bool dbReady (const string& dbname, const string& dbpath ) { string dictfilename = dbpath + dbname + DICT_TAG; string datadirname = dbpath + dbname + DBDIR_TAG; string dbinfofilename = dbpath + dbname + DBINFO_TAG; if ( file_exists(dbinfofilename) && file_exists(dictfilename) && dir_exists(datadirname)) { return true; } else { cerr << "Database is not ready. One of these files/directories are missing: \n" << dbinfofilename << endl << dictfilename << endl << datadirname << endl; return false; } }
bool setup_binds(setup_vals * setup) { printf("binds: %d\n", setup->dircount); bool ret = true; //Bind newdir int x = mount(setup->newroot, setup->newroot, NULL, MS_BIND, NULL); if (x != 0) { perror("Could not bind new root"); ret = false; } for(int i = 0; i < setup->dircount; i++) { if(strcmp(setup->bind_dirs[i], "/etc") == 0) setup->bound_etc = true; } char ** bind_dirs = realloc(setup->bind_dirs, sizeof(char *) * (setup->dircount + 1)); if(!bind_dirs) fatal(-1, true, "Failed to allocate for bind_dirs"); if(!setup->bound_etc) setup->bind_dirs[setup->dircount++] = "/etc"; for(int i = 0; i < setup->dircount; i++) { char * target = safemalloc(sizeof(char) * (strlen(setup->newroot) + 1 + strlen(setup->bind_dirs[i]) + 1)); strcpy(target, setup->newroot); strcat(target, "/"); strcat(target, setup->bind_dirs[i]); if(!dir_exists(target)) { printf("Creating directory %s\n", target); mkdir(target, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); } printf("Binding %s to %s\n", setup->bind_dirs[i], target); int x = mount(setup->bind_dirs[i], target, NULL, MS_BIND, NULL); if (x != 0) { perror("Bind Failed"); ret = false; } else printf("Successfully bound %s\n", setup->bind_dirs[i]); } return ret; }
void add_java_home_to_path(void) { const char *java_home = get_java_home(); struct string *new_path = string_init(32), *buffer; const char *env; if (!java_home) return; buffer = string_initf("%s/bin", java_home); if (dir_exists(buffer->buffer)) string_append_path_list(new_path, buffer->buffer); string_setf(buffer, "%s/jre/bin", java_home); if (dir_exists(buffer->buffer)) string_append_path_list(new_path, buffer->buffer); env = getenv("PATH"); string_append_path_list(new_path, env ? env : get_ij_dir()); setenv_or_exit("PATH", new_path->buffer, 1); string_release(buffer); string_release(new_path); }
int remove_on_empty_main(const char *controller, const char *cgroup, struct ucred p, struct ucred r) { char rcgpath[MAXPATHLEN]; size_t cgroup_len; nih_local char *working = NULL, *wcgroup = NULL; if (!sane_cgroup(cgroup)) { nih_error("%s: unsafe cgroup", __func__); return -1; } // Get r's current cgroup in rcgpath if (!compute_pid_cgroup(r.pid, controller, "", rcgpath, NULL)) { nih_error("%s: Could not determine the requested cgroup", __func__); return -1; } cgroup_len = strlen(cgroup); if (strlen(rcgpath) + cgroup_len > MAXPATHLEN) { nih_error("%s: Path name too long", __func__); return -1; } wcgroup = NIH_MUST( nih_strdup(NULL, cgroup) ); if (!normalize_path(wcgroup)) return -1; working = NIH_MUST( nih_strdup(NULL, rcgpath) ); NIH_MUST( nih_strcat(&working, NULL, "/") ); NIH_MUST( nih_strcat(&working, NULL, wcgroup) ); if (!dir_exists(working)) { return -1; } // must have write access if (!may_access(r.pid, r.uid, r.gid, working, O_WRONLY)) { nih_error("%s: pid %d (%u:%u) may not remove %s", __func__, r.pid, r.uid, r.gid, working); return -1; } NIH_MUST( nih_strcat(&working, NULL, "/notify_on_release") ); if (!set_value_trusted(working, "1\n")) { nih_error("Failed to set remove_on_empty for %s:%s", controller, working); return -1; } return 0; }
void getcfg() { char* __homedir="/sdcard/"; int i; if (__homedir==NULL) { strcpy(__configPath, configfile_fallback); // если у юзера отсутствует домашний каталог, то держим все данные прямо здесь, рядом } else { strcpy(__configPath, __homedir); strcat(__configPath, "/"); // на всякий случай добавляем слэш if (!dir_exists(__configPath)) { printf("Пытаемся создать каталог для конфига\n"); mkdir_p(__configPath, 0666); } strcat(__configPath, configfile); } FILE *f; if (access(__configPath, R_OK) == -1) { printf("Конфиг не существует, пытаемся скопировать дефолтный...\n"); f=fopen(__configPath, "w"); if (!f) { printf("Не получается записать дефолтный конфиг! =(\n"); } else { fputs(configtext_default, f); fclose(f); } } char* config=file_get_contents(__configPath); if (config!=NULL) { struct list config_lines=split(config, "\n"); if (config_lines.length<2) { printf ("Формат конфига неверный, пропускаем.\n"); } else { sscanf(config_lines.index[0], "%d:%d:%d:%d", &start_lessons[0], &start_lessons[1], &localtime_offset, ¬ify_offset); sscanf(config_lines.index[1], "%d:%d:%d", &count_lessons, &lesson_length, &default_break); } for (i=2; i<config_lines.length; i++) { if ((i-2)>BREAKS_MAX_INDEX) break; sscanf(config_lines.index[i], "%d", &breaks_in_minutes[i-2]); } } else { printf("Невозможно прочесть конфиг, используются значения по-умолчанию.\n"); } }
void PPTKQsubBash::on_write_clicked() { if (!dir_exists(m_save_dir_edit->text())) { return; } on_preview_clicked(); QString fwn = QDir(m_save_dir_edit->text()).filePath(m_save_filename_edit->text()); std::FILE* fw = std::fopen(fwn.toStdString().c_str(), "w"); std::fprintf(fw, "%s", m_preview_edit->toPlainText().toStdString().c_str()); std::fclose(fw); }
/* Returns 1 if dir exists, 0 if not. Note: I'm never going to check for the * -1, which is why the size is MAX_MSG_LEN+128. It's easy to tell when * that amount will be exceeded. */ int vdir_exists(const char *fmt, ...) { char path[MAX_MSG_LEN+128]; va_list ap; int ret; va_start(ap, fmt); ret = vsnprintf(path, MAX_MSG_LEN+128, fmt, ap); if (ret >= MAX_MSG_LEN+128) return -1; ret = dir_exists(path); va_end(ap); return ret; }
static int rmkdir(char *path) { /* * strip off trailing components unless we can stat the directory, or we * have run out of components */ char *i = rindex(path, '/'); if (path[0] == '\0' || dir_exists(path)) return 0; if (i != NULL) { *i = '\0'; rmkdir(path); *i = '/'; mkdir(path, 0777); } return dir_exists(path) ? 0 : -1; }