bool check_db(const char *lang) { char *dbname = join_path (lang, "dict.db"); bool retval = file_exists(dbname); free(dbname); return retval; }
void OnClickLoad(std::string filename) { std::string fullname = join_path(GetFullSavefileDirPath().c_str(), filename.c_str(), 0); if (Pi::IsGameStarted()) Pi::EndGame(); Pi::UninitGame(); Pi::InitGame(); try { Serializer::LoadGame(fullname.c_str()); } catch (SavedGameCorruptException) { Gui::Screen::ShowBadError(Lang::GAME_LOAD_CORRUPT); Pi::UninitGame(); Pi::InitGame(); Pi::SetView(Pi::gameMenuView); // Pi::currentView is unset, set it back to the gameMenuView return; } catch (CouldNotOpenFileException) { Gui::Screen::ShowBadError(Lang::GAME_LOAD_CANNOT_OPEN); Pi::UninitGame(); Pi::InitGame(); Pi::SetView(Pi::gameMenuView); // Pi::currentView is unset, set it back to the gameMenuView return; } Pi::StartGame(); // Pi::currentView is unset, but this view is still shown, so // must un-show it Pi::SetView(Pi::gameMenuView); Pi::SetView(Pi::worldView); }
void __prefix_cwd(const char* in_path) { if (!*in_path) return; std::string path; std::list<std::string> path_components; // std::cout << "CWD to " << in_path << std::endl; pthread_rwlock_wrlock(&g_cwdLock); if (in_path[0] != '/') { path = g_cwd; path += in_path; } else path = in_path; path_components = explode_path(path); g_cwd = join_path(canonicalize_path(path_components)); if (g_cwd[g_cwd.length()-1] != '/') g_cwd += '/'; // std::cout << "\t+++ CWD In: " << in_path << "; out: " << g_cwd << std::endl; pthread_rwlock_unlock(&g_cwdLock); }
static int file_size(char *folder_path, char *file_name) { struct stat st; char *path = join_path(folder_path, file_name); stat(path, &st); free(path); return st.st_size; }
END_TEST START_TEST(test_join_path_with_slash) { char *s1 = "/tmp/path/"; char *s2 = "file"; char *s3 = join_path(s1, s2); fail_unless(strcmp(s3, "/tmp/path/file") == 0); }
Dictionary dictionary_create_from_db(const char *lang) { char *dbname; const char * t; Dictionary dict; Dict_node *dict_node; dict = (Dictionary) xalloc(sizeof(struct Dictionary_s)); memset(dict, 0, sizeof(struct Dictionary_s)); dict->version = NULL; dict->num_entries = 0; dict->affix_table = NULL; dict->regex_root = NULL; /* Language and file-name stuff */ dict->string_set = string_set_create(); dict->lang = lang; t = strrchr (lang, '/'); if (t) dict->lang = string_set_add(t+1, dict->string_set); /* To disable spell-checking, just set the checker to NULL */ dict->spell_checker = spellcheck_create(dict->lang); dict->base_knowledge = NULL; dict->hpsg_knowledge = NULL; dbname = join_path (lang, "dict.db"); dict->name = string_set_add(dbname, dict->string_set); free(dbname); /* Set up the database */ dict->db_handle = object_open(dict->name, db_open, NULL); dict->lookup_list = db_lookup_list; dict->free_lookup = db_free_llist; dict->lookup = db_lookup; dict->close = db_close; /* Misc remaining common (generic) dict setup work */ dict->left_wall_defined = boolean_dictionary_lookup(dict, LEFT_WALL_WORD); dict->right_wall_defined = boolean_dictionary_lookup(dict, RIGHT_WALL_WORD); dict->empty_word_defined = boolean_dictionary_lookup(dict, EMPTY_WORD_MARK); dict->unknown_word_defined = boolean_dictionary_lookup(dict, UNKNOWN_WORD); dict->use_unknown_word = true; dict_node = dictionary_lookup_list(dict, UNLIMITED_CONNECTORS_WORD); if (dict_node != NULL) { dict->unlimited_connector_set = connector_set_create(dict_node->exp); } else { dict->unlimited_connector_set = NULL; } free_lookup_list(dict, dict_node); return dict; }
ussval_t* builtin_path_join(__unused ussenv_t* e, ussval_t* a) { UASSERT_NUM("path-join", a, 2); UASSERT_TYPE("path-join", a, 0, UVAL_STR); UASSERT_TYPE("path-join", a, 1, UVAL_STR); ussval_t* l = ussval_pop(a, 0); ussval_t* r = ussval_pop(a, 0); return ussval_new_str(join_path(l->str, true, r->str)); }
static struct node *read_fstree(const char *dirname) { DIR *d; struct dirent *de; struct stat st; struct node *tree; d = opendir(dirname); if (!d) die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); tree = build_node(NULL, NULL); while ((de = readdir(d)) != NULL) { char *tmpnam; if (streq(de->d_name, ".") || streq(de->d_name, "..")) continue; tmpnam = join_path(dirname, de->d_name); if (lstat(tmpnam, &st) < 0) die("stat(%s): %s\n", tmpnam, strerror(errno)); if (S_ISREG(st.st_mode)) { struct property *prop; FILE *pfile; pfile = fopen(tmpnam, "r"); if (! pfile) { fprintf(stderr, "WARNING: Cannot open %s: %s\n", tmpnam, strerror(errno)); } else { prop = build_property(xstrdup(de->d_name), data_copy_file(pfile, st.st_size)); add_property(tree, prop); fclose(pfile); } } else if (S_ISDIR(st.st_mode)) { struct node *newchild; newchild = read_fstree(tmpnam); newchild = name_node(newchild, xstrdup(de->d_name)); add_child(tree, newchild); } free(tmpnam); } closedir(d); return tree; }
Dictionary dictionary_create_from_db(const char *lang) { char *dbname; const char * t; Dictionary dict; Dict_node *dict_node; dict = (Dictionary) xalloc(sizeof(struct Dictionary_s)); memset(dict, 0, sizeof(struct Dictionary_s)); /* Language and file-name stuff */ dict->string_set = string_set_create(); t = strrchr (lang, '/'); t = (NULL == t) ? lang : t+1; dict->lang = string_set_add(t, dict->string_set); lgdebug(D_USER_FILES, "Debug: Language: %s\n", dict->lang); /* To disable spell-checking, just set the checker to NULL */ dict->spell_checker = spellcheck_create(dict->lang); #if defined HAVE_HUNSPELL || defined HAVE_ASPELL if (NULL == dict->spell_checker) prt_error("Info: Spell checker disabled."); #endif dict->base_knowledge = NULL; dict->hpsg_knowledge = NULL; dbname = join_path (lang, "dict.db"); dict->name = string_set_add(dbname, dict->string_set); free(dbname); /* Set up the database */ dict->db_handle = object_open(dict->name, db_open, NULL); dict->lookup_list = db_lookup_list; dict->free_lookup = db_free_llist; dict->lookup = db_lookup; dict->close = db_close; /* Misc remaining common (generic) dict setup work */ dict->left_wall_defined = boolean_dictionary_lookup(dict, LEFT_WALL_WORD); dict->right_wall_defined = boolean_dictionary_lookup(dict, RIGHT_WALL_WORD); dict->empty_word_defined = boolean_dictionary_lookup(dict, EMPTY_WORD_MARK); dict->unknown_word_defined = boolean_dictionary_lookup(dict, UNKNOWN_WORD); dict->use_unknown_word = true; dict_node = dictionary_lookup_list(dict, UNLIMITED_CONNECTORS_WORD); if (dict_node != NULL) dict->unlimited_connector_set = connector_set_create(dict_node->exp); free_lookup_list(dict, dict_node); return dict; }
char *search_paths(char **paths, char *filename) { char *result = NULL, *candidate; strarray_each(paths, char *path) { candidate = join_path(path, filename); if (is_file(candidate)) { result = candidate; break; } free(candidate); }
bool check_join_path(const char *dir, const char *file, const char *check) { char *joined = join_path(dir, file); bool ok = strcmp(check, joined) == 0; printf( "'%s' + '%s' = '%s' (%s)\n", dir, file, joined, ok ? "ok" : "FAILED" ); free(joined); return ok; }
static void fs_touch(Store *store, const char *filename) { int f; char path[MAX_FILE_PATH]; join_path(path, store->dir.path, filename); if ((f = creat(path, store->file_mode)) == 0) { RAISE(IO_ERROR, "couldn't create file %s: <%s>", path, strerror(errno)); } close(f); }
static void bind_list_apply(const char *root, struct bind_list *list) { for (; list; list = list->next) { char *dst = join_path(root, list->arg); // Only use MS_REC with writable mounts to work around a kernel bug: // https://bugzilla.kernel.org/show_bug.cgi?id=24912 mountx(list->arg, dst, "bind", MS_BIND | (list->read_only ? 0 : MS_REC), NULL); if (list->read_only) mountx(list->arg, dst, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL); free(dst); } }
static void fill_json_file_entry(char *path, struct dirent *ep, void *data) { json_object *json_file_entry = (json_object *)data; char *url = join_path(path + strlen("../public/") , ep->d_name); int size = file_size(path, ep->d_name); json_object_object_add(json_file_entry, "name", json_object_new_string(ep->d_name)); json_object_object_add(json_file_entry, "url", json_object_new_string(url)); json_object_object_add(json_file_entry, "size", json_object_new_int(size)); free(url); }
/** * Callback used with SBF to generate file names. */ static int bloomf_sbf_callback(void* in, uint64_t bytes, bloom_bitmap *out) { // Cast the input pointer bloom_filter *filt = in; // Check if we are in-memory if (filt->filter_config.in_memory) { syslog(LOG_INFO, "Creating new in-memory bitmap for filter %s. Size: %llu", filt->filter_name, (unsigned long long)bytes); return bitmap_from_file(-1, bytes, ANONYMOUS, out); } // Scan through the folder looking for data files struct dirent **namelist = NULL; int num_files; // Filter only data dirs, in sorted order num_files = scandir(filt->full_path, &namelist, filter_data_files, NULL); syslog(LOG_INFO, "Found %d files for filter %s.", num_files, filt->filter_name); if (num_files < 0) { syslog(LOG_ERR, "Error discovering files for filter '%s'. %s", filt->filter_name, strerror(errno)); return -1; } // Free the memory associated with scandir for (int i=0; i < num_files; i++) { free(namelist[i]); } if (namelist) free(namelist); // Generate the new file name char *filename = NULL; int file_name_len; file_name_len = asprintf(&filename, DATA_FILE_NAME, num_files); assert(file_name_len != -1); // Get the full path char *full_path = join_path(filt->full_path, filename); free(filename); syslog(LOG_INFO, "Creating new file: %s for filter %s. Size: %llu", full_path, filt->filter_name, (unsigned long long)bytes); // Create the bitmap bitmap_mode mode = (filt->config->use_mmap) ? SHARED : PERSISTENT; int res = bitmap_from_filename(full_path, bytes, 1, mode, out); if (res) { syslog(LOG_CRIT, "Failed to create new file: %s for filter %s. Err: %s", full_path, filt->filter_name, strerror(errno)); } free(full_path); return res; }
static off_t fs_length(Store *store, const char *filename) { char path[MAX_FILE_PATH]; struct stat stt; if (stat(join_path(path, store->dir.path, filename), &stt)) { RAISE(IO_ERROR, "getting lenth of %s: <%s>", path, strerror(errno)); } return stt.st_size; }
TempDir::TempDir(const string& appName) { for (int i=(std::rand()%0xffff); ; ++i) { m_path = join_path(get_temp_path(), appName + convert_to<string>(i)); if (!directory_exists(m_path)) { make_directory(m_path); break; } } }
int make_linked_temp_file (std::string& dest, const char* tmpdir, const char* prefix) { if (!prefix) prefix = DEFAULT_TEMP_FILE_PREFIX; std::string dirname (temp_dir (tmpdir)); std::string templ = join_path (dirname.c_str (), prefix, NULL); templ += TEMP_FILE_TEMPL_SUFFIX; MemWrapper <char> buffer (templ.size () + 1); strcpy (buffer, templ.c_str ()); int fhandle = mkstemp (buffer); dest = buffer; return fhandle; }
void newton_init(struct simulation *sim, char *solver_name) { printf_log(sim, _("Solver initialization\n")); char lib_name[100]; char lib_path[1000]; sprintf(lib_name, "%s.so", solver_name); join_path(2, lib_path, get_plugins_path(sim), lib_name); printf_log(sim, "I want to open %s %s %s\n", lib_path, get_plugins_path(sim), lib_name); char *error; dll_handle = dlopen(lib_path, RTLD_LAZY); if (!dll_handle) { fprintf(stderr, "%s\n", dlerror()); exit(0); } dll_solve_cur = dlsym(dll_handle, "dll_solve_cur"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_newton_set_min_ittr = dlsym(dll_handle, "dll_newton_set_min_ittr"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_set_interface = dlsym(dll_handle, "set_interface"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_solver_realloc = dlsym(dll_handle, "dll_solver_realloc"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_solver_free_memory = dlsym(dll_handle, "dll_solver_free_memory"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } (*dll_newton_set_min_ittr) (0); }
bool TestPathops::process () { #ifdef _MSC_VER const char* paths [] = {"\\kokos\\banan", "d:\\Encyclopedia\\Data\\Genomes\\E.coli.K12\\proteins\\fasta\\", "", "\\", "\\ananas\\", NULL}; #else const char* paths [] = {"/kokos/banan", "~/Encyclopedia/Data/Genomes/E.coli.K12/proteins/fasta/", "", "/", "/ananas/", NULL}; #endif const char** path = paths; for (; *path != NULL; path ++) { o_ << "Path " << *path << std::endl; StrVec comps = split_path (*path); o_ << "path " << *path << ", " << comps.size () << " components" << std::endl; StrVec::const_iterator i = comps.begin (); for (;i < comps.end (); i ++) o_ << " '" << (*i).c_str () << "'" << std::endl; std::string rejoined = join_path (comps); o_ << " Rejoined: " << rejoined.c_str () << std::endl; } std::string jp = join_path ("kokos", "banan", "ananas", "yabloko", NULL); o_ << jp.c_str () << std::endl; jp = join_path ("", "kokos", NULL); o_ << jp.c_str () << std::endl; jp = join_path ("", NULL); o_ << jp.c_str () << std::endl; jp = join_path ("kokos", NULL); o_ << jp.c_str () << std::endl; jp = join_path (NULL); o_ << jp.c_str () << std::endl; return true; }
int main(int argc, char** argv) { GC_INIT(); ussenv_t *e = ussenv_new(); ussenv_common_builtins(e); char *prelude_path = join_path(STDLIB_PATH, true, "prelude.uss"); ussval_t *prelude = ussval_eval_from_file(e, prelude_path); /* If the result is an error be sure to print it */ if (prelude->type == UVAL_ERR) { ussval_println(prelude); } ussval_del(prelude); fprintf(stderr, "argv[0]=%s argv[1]=%s\n", argv[0], argv[1]); if (argc >= 2) { /* loop over each supplied filename (starting from 1) */ for (int i = 1; i < argc; i++) { ussval_t *x = ussval_eval_from_file(e, argv[i]); /* If the result is an error be sure to print it */ if (x->type == UVAL_ERR) { ussval_println(x); } ussval_del(x); } } else { char buf[4096]; parser_t *parser = parser_toplevel(); mpc_result_t r; ussval_t *x = UVAL_NIL; while(fgets(buf, sizeof(buf), stdin)) { if (mpc_parse("<stdin>", buf, parser->uss, &r)) { // mpc_ast_print(r.output); x = ussval_eval(e, ussval_read(r.output)); mpc_ast_delete(r.output); } else { mpc_err_print(r.error); mpc_err_delete(r.error); } } ussval_println(x); parser_cleanup(parser); } ussenv_del(e); return 0; }
/** Update the include path * * @return include filepaths * * The include path are the directories, in which all includes will be * searched for. */ const std::vector<std::string>& KeyFile::get_include_dirs(bool _update) { if (!_update) return include_dirs; // lets take the long way ... std::set<std::string> new_include_dirs; // dir of file std::string directory = ""; auto my_filepath = get_filepath(); size_t pos = my_filepath.find_last_of("/\\"); if (pos != std::string::npos) directory = my_filepath.substr(0, pos) + "/"; if (!directory.empty()) new_include_dirs.insert(directory); // update for (auto& kw : include_path_keywords) { auto kw_inc_path = std::static_pointer_cast<IncludePathKeyword>(kw); bool is_relative_dir = kw_inc_path->is_relative(); // append for (const auto& dirpath : kw_inc_path->get_include_dirs()) { if (is_relative_dir) new_include_dirs.insert(join_path(directory, dirpath)); else new_include_dirs.insert(dirpath); } } // check also the includes for (auto& include_kw : include_keywords) for (auto& include_kf : include_kw->get_includes()) { auto paths = include_kf->get_include_dirs(true); new_include_dirs.insert(paths.begin(), paths.end()); } #ifdef QD_DEBUG std::cout << "Include dirs:\n"; for (const auto& entry : include_dirs) std::cout << entry << '\n'; #endif include_dirs = std::vector<std::string>(new_include_dirs.begin(), new_include_dirs.end()); return include_dirs; }
static Lock *fs_open_lock_i(Store *store, const char *lockname) { Lock *lock = ALLOC(Lock); char lname[100]; char path[MAX_FILE_PATH]; snprintf(lname, 100, "%s%s.lck", LOCK_PREFIX, lockname); lock->name = estrdup(join_path(path, store->dir.path, lname)); lock->store = store; lock->obtain = &fs_lock_obtain; lock->release = &fs_lock_release; lock->is_locked = &fs_lock_is_locked; return lock; }
static void fill_json_files_array(char *path, struct dirent *ep, void *data) { if (ep->d_type != DT_DIR) return; json_object *json_files_array = (json_object *)data; json_object *json_file_entry = json_object_new_object(); char *folder_path = join_path(path, ep->d_name); traverse_directory(folder_path, fill_json_file_entry, json_file_entry); json_object_array_add(json_files_array, json_file_entry); free(folder_path); }
static void remove_path(char *path, int options) { struct stat st; // Stat file if (stat(path, &st) < 0) { perror(path); return; } if (S_ISDIR(st.st_mode)) { struct dirent *dp; DIR *dirp; char *fn; int more; // Remove files in directory recursively if (options & VERBOSE) printf("deleting all files in %s\n", path); dirp = opendir(path); if (!dirp) { perror(path); return; } // Keep scanning directory until it is empty more = 1; while (more) { more = 0; while ((dp = readdir(dirp))) { more = 1; fn = join_path(path, dp->d_name); if (!fn) { fprintf(stderr, "error: out of memory\n"); closedir(dirp); return; } remove_path(fn, options); } if (more) rewinddir(dirp); } closedir(dirp); // Remove directory if (options & VERBOSE) printf("removing directory %s\n", path); if (rmdir(path) < 0) perror(path); } else { // Remove file if (options & VERBOSE) printf("removing file %s\n", path); if (unlink(path) < 0) perror(path); } }
Dictionary dictionary_create_from_file(const char * lang) { Dictionary dictionary; init_memusage(); if (lang && *lang) { char * dict_name; char * pp_name; char * cons_name; char * affix_name; char * regex_name; dict_name = join_path(lang, "4.0.dict"); pp_name = join_path(lang, "4.0.knowledge"); cons_name = join_path(lang, "4.0.constituent-knowledge"); affix_name = join_path(lang, "4.0.affix"); regex_name = join_path(lang, "4.0.regex"); dictionary = dictionary_six(lang, dict_name, pp_name, cons_name, affix_name, regex_name); free(regex_name); free(affix_name); free(cons_name); free(pp_name); free(dict_name); } else { prt_error("Error: No language specified!"); dictionary = NULL; } return dictionary; }
/** Resolve an include * * @param _filepath path of the include * @return filepath resolved filepath */ std::string KeyFile::resolve_include_filepath(const std::string& _filepath) { if (check_ExistanceAndAccess(_filepath)) return _filepath; for (const auto& dir : include_dirs) { auto full_path = join_path(dir, _filepath); if (check_ExistanceAndAccess(full_path)) return full_path; } throw(std::invalid_argument("Can not find: " + _filepath)); }
char *seek_true_path(char *path, char *actual_dir) { char **tmp; tmp = ft_strsplit(actual_dir, '/'); while (path && *path) { if (*path == '/' || (*path == '.' && !*(path + 1))) ++path; else if (*path == '.' && *(path + 1) == '/') path += 2; else if (*path == '.' && *(path + 1) == '.') { tmp = suppr_last_dir(tmp); path += 3; } else path += add_dir(&tmp, path); } if (*actual_dir == '~') return (join_path(tmp, 1)); else return (join_path(tmp, 0)); }
static void fill_fullpaths(struct node *tree, const char *prefix) { struct node *child; const char *unit; tree->fullpath = join_path(prefix, tree->name); unit = strchr(tree->name, '@'); if (unit) tree->basenamelen = unit - tree->name; else tree->basenamelen = strlen(tree->name); for_each_child(tree, child) fill_fullpaths(child, tree->fullpath); }
static int fs_exists(Store *store, const char *filename) { int fd; char path[MAX_FILE_PATH]; join_path(path, store->dir.path, filename); fd = open(path, 0); if (fd < 0) { if (errno != ENOENT) { RAISE(IO_ERROR, "checking existance of %s: <%s>", path, strerror(errno)); } return false; } close(fd); return true; }