Test(test_pathutils, test_find_file_in_path) { gchar *file; file = find_file_in_path("/dev", "null", G_FILE_TEST_EXISTS); cr_assert_str_eq(file, "/dev/null"); g_free(file); file = find_file_in_path("/home:/dev:/root", "null", G_FILE_TEST_EXISTS); cr_assert_str_eq(file, "/dev/null"); g_free(file); }
char * my_path(char * to, const char *progname, const char *own_pathname_part) { char *start, *end, *prog; size_t to_length; DBUG_ENTER("my_path"); start=to; /* Return this */ if (progname && (dirname_part(to, progname, &to_length) || find_file_in_path(to,progname) || ((prog=getenv("_")) != 0 && dirname_part(to, prog, &to_length)))) { (void) intern_filename(to,to); if (!test_if_hard_path(to)) { if (!my_getwd(curr_dir,FN_REFLEN,MYF(0))) bchange((uchar*) to, 0, (uchar*) curr_dir, strlen(curr_dir), strlen(to)+1); } } else { if ((end = getenv("MY_BASEDIR_VERSION")) == 0 && (end = getenv("MY_BASEDIR")) == 0) { #ifdef DEFAULT_BASEDIR end= (char*) DEFAULT_BASEDIR; #else end= (char*) "/my/"; #endif } (void) intern_filename(to,end); to=strend(to); if (to != start && to[-1] != FN_LIBCHAR) *to++ = FN_LIBCHAR; (void) strmov(to,own_pathname_part); } DBUG_PRINT("exit",("to: '%s'",start)); DBUG_RETURN(start); } /* my_path */
gboolean cfg_lexer_include_file(CfgLexer *self, const gchar *filename_) { struct stat st; gchar *filename; if (self->include_depth >= MAX_INCLUDE_DEPTH - 1) { msg_error("Include file depth is too deep, increase MAX_INCLUDE_DEPTH and recompile", evt_tag_str("filename", filename_), evt_tag_int("depth", self->include_depth)); return FALSE; } filename = find_file_in_path(_get_include_path(self), filename_, G_FILE_TEST_EXISTS); if (!filename || stat(filename, &st) < 0) { if (filename) g_free(filename); if (cfg_lexer_include_file_glob(self, filename_)) return TRUE; msg_error("Include file/directory not found", evt_tag_str("filename", filename_), evt_tag_str("include-path", _get_include_path(self)), evt_tag_error("error")); return FALSE; } else { gboolean result; result = cfg_lexer_include_file_simple(self, filename); g_free(filename); return result; } }