t_lst *manage_av_file(char *path, t_lst *lst, DIR *dir) { char *formated; struct dirent *ret; formated = format_path(path); if (!formated) return (NULL); if (!(dir = opendir(formated))) { ft_error(path); return (NULL); } else { while ((ret = readdir(dir))) if ((ft_strcmp(ret->d_name, get_file_name(path)) == 0)) { lst = ft_get_data(lst, ret->d_name, path); break ; } if (!lst) return (NULL); closedir(dir); return (lst); } return (NULL); }
static int hook_close(struct tracy_event *e) { int rc = TRACY_HOOK_CONTINUE; struct multiboot_child_data *mbc = e->child->custom; if (e->child->pre_syscall) { int fd = (int)e->args.a0; struct tracy_ll_item *item = ll_find(mbc->files, fd); if (item) { struct fd_info *fdi = item->data; ERROR("close(%d|%s)\n", fd, fdi->filename); // TODO detect format if (fs_was_format(fdi)) { DEBUG("FORMAT DETECTED!\n"); struct fstab_rec *fstabrec = get_fstab_rec(fdi->filename); if (fstabrec) { INFO("format path %s...\n", fstabrec->replacement_device); char buf[PATH_MAX]; snprintf(buf, sizeof(buf), "%s/*", fstabrec->replacement_device); format_path(buf); } } free_fdinfo(fdi); ll_del(mbc->files, fd); } } return rc; }
/*! \brief Finds absolute path. \details Defined in dmzSystemFile.h. \param[in] Path String containing path used to find the absolute (a.k.a. canonical) path \param[out] absPath String in which the found absolute path is stored. \return Returns dmz::True if absolute path is found. */ dmz::Boolean dmz::get_absolute_path (const String &Path, String &absPath) { Boolean result (False); if (is_valid_path (Path)) { if (is_directory (Path)) { const PushDirectory Push (Path); if (Push.is_valid ()) { result = True; absPath = get_current_directory (); } } else { String spath, file, ext; split_path_file_ext (Path, spath, file, ext); if (!spath) { spath = "."; } const PushDirectory Push (spath); if (Push.is_valid ()) { result = True; absPath.flush () << get_current_directory () << file << ext; } } absPath = format_path (absPath); } else { absPath.flush (); } return result; }
/*! \brief Loads session data. \details Attempts to load session data using the \a Name and \a Domain from the constructor. The session file for the various platforms is as follows: - Win32 \$(HOME)/\$(Domain)/\$(Name).xml - MacOS ~/Library/Preferences/\$(Domain)/\$(Name).xml - Linux ~/.\$(Domain)/\$(Name).xml \return Returns dmz::True if the session data was read successfully. */ dmz::Boolean dmz::ApplicationiPhone::load_session () { Boolean result (True); _state.sessionDir = dmz_get_document_directory (); if (_state.sessionDir) { _state.sessionFile << "session.xml"; _state.sessionPath = format_path (_state.sessionDir + "/" + _state.sessionFile); if (is_valid_path (_state.sessionPath)) { Config data ("global"); if (xml_to_config (_state.sessionPath, data, &(_state.log))) { if (!_state.quiet) { _state.log.info << "Loaded session file: " << _state.sessionPath << endl; } Config session; _state.rt.get_session_config (session); if (data.lookup_all_config_merged (session.get_name (), session)) { const String DefaultDir (config_to_string (DefaultDirName, session)); if (DefaultDir && is_valid_path (DefaultDir)) { _state.appState.set_default_directory (DefaultDir); } else { _state.appState.set_default_directory (dmz_get_main_bundle_directory ()); } _state.rt.set_session_config (session); } } else { _state.log.error << "Failed parsing session file: " << _state.sessionPath << endl; } } else if (!_state.quiet) { _state.log.info << "Session file: " << _state.sessionPath << " does not exist" << endl; result = False; } } return result; }
/*! \brief Gets current working directory. \details Defined in dmzSystemFile.h. \return Returns String containing current working directory. */ dmz::String dmz::get_current_directory () { String result; char path[MAXPATHLEN]; if (getcwd (path, MAXPATHLEN)) { result << path << "/"; } return format_path (result); }
char init_t_file(t_file **file, char *root, char *name) { struct stat *stat_var; char *path; my_malloc((void*)&stat_var, sizeof(struct stat)); my_malloc((void*)file, sizeof(t_file)); path = name; if (my_strcmp(root, name)) path = format_path(root, name); if (lstat(path, stat_var) == -1) { perror(my_strcat("my_ls: ", name)); return (0); } (*file)->name = name; (*file)->stat = stat_var; (*file)->is_dir = S_ISDIR(stat_var->st_mode); return (1); }
/*! \brief Finds file on file system. \ingroup System \details Defined in dmzSystemFile.h. This function takes three steps to locate the file. First it attempts to validate the file as it is passed in. If the file is not found. All leading path information is stripped from the file and then each path in the StringContainer is used to try and locate the file. If the file is not found, each path in the StringContainer is searched with out the leading path information stripped from the \a FileName. \param[in] Container StringContainer with list of paths to use in the file search. \param[in] FileName String containing the name of the file to search for. \param[out] foundFile String containing the absolute path to the found file. \return Returns dmz::True if the file is found. */ dmz::Boolean dmz::find_file ( const StringContainer &Container, const String &FileName, String &foundFile) { Boolean result (False); if (is_valid_path (FileName)) { result = get_absolute_path (FileName, foundFile); } if (!result) { String path, file, ext; split_path_file_ext (FileName, path, file, ext); if (file) { file << ext; Boolean done (!Container.get_first (path)); while (!done) { const String CleanPath (format_path (path + "/" + file)); if (is_valid_path (CleanPath)) { result = get_absolute_path (CleanPath, foundFile); done = True; } else { done = !Container.get_next (path); } } } } if (!result) { String path; Boolean done (!Container.get_first (path)); while (!done) { const String CleanPath (format_path (path + "/" + FileName)); if (is_valid_path (CleanPath)) { result = get_absolute_path (CleanPath, foundFile); done = True; } else { done = !Container.get_next (path); } } } return result; }
/*! \brief Splits a path into the directory, file name, and file extension. \ingroup System \details Defined in dmzSystemFile.h. The \a FullPath is formatted before processing. The file extension is returned with the leading period. If either a path or extension is not found in the \a FullPath, the corresponding return value is an empty string. \param[in] FullPath String containing full path to be split up. \param[out] path String containing the directory component of the \a FullPath. \param[out] file String containing the file component of the \a FullPath. \param[out] ext String containing the extension of the \a FullPath. */ void dmz::split_path_file_ext ( const String &FullPath, String &path, String &file, String &ext) { path = format_path (FullPath); file.flush (); ext.flush (); const Int32 Length = path.get_length (); Int32 slashFound = -1; Int32 index = Length - 1; Boolean done (False); while (!done) { if (path.get_char (index) == '/') { slashFound = index; done = True; } else { index--; if (index < 0) { done = True; } } } if (slashFound >= 0) { file = path.get_sub (slashFound + 1); path = path.get_sub (0, slashFound); } else { file = path; path.flush (); } if (file) { const Int32 FileLength = file.get_length (); Int32 dotFound = -1; index = FileLength - 1; done = False; while (!done) { if (file.get_char (index) == '.') { dotFound = index; done = True; } else { index--; if (index < 0) { done = True; } } } if (dotFound > 0) { ext = file.get_sub (dotFound); file = file.get_sub (0, dotFound - 1); } } }
/*! \brief Loads session data. \details Attempts to load session data using the \a Name and \a Domain from the constructor. The session file for the various platforms is as follows: - Win32 \$(HOME)/\$(Domain)/\$(Name).xml - MacOS ~/Library/Preferences/\$(Domain)/\$(Name).xml - Linux ~/.\$(Domain)/\$(Name).xml \return Returns dmz::True if the session data was read successfully. */ dmz::Boolean dmz::Application::load_session () { Boolean result (True); _state.sessionDir = get_home_directory (); if (is_valid_path (_state.sessionDir)) { #if defined (_WIN32) if (_state.Domain) { _state.sessionDir << "/" << _state.Domain; } else { _state.sessionDir << "/dmz"; } #elif defined (__APPLE__) || defined (MACOSX) _state.sessionDir << "/Library/Preferences"; if (_state.Domain) { _state.sessionDir << "/" << _state.Domain; } else { _state.sessionDir << "/dmz"; } #else if (_state.Domain) { _state.sessionDir << "/." << _state.Domain; } else { _state.sessionDir << "/.dmz"; } #endif } else { result = False; } if (_state.sessionDir) { if (_state.Name) { _state.sessionFile << _state.Name << ".xml"; } else { _state.sessionFile << "session.xml"; } _state.sessionPath = format_path (_state.sessionDir + "/" + _state.sessionFile); if (is_valid_path (_state.sessionPath)) { Config data ("global"); if (xml_to_config (_state.sessionPath, data, &(_state.log))) { if (!_state.quiet) { _state.log.info << "Loaded session file: " << _state.sessionPath << endl; } Config session; _state.rt.get_session_config (session); if (data.lookup_all_config_merged (session.get_name (), session)) { const String DefaultDir (config_to_string (DefaultDirName, session)); if (DefaultDir && is_valid_path (DefaultDir)) { _state.appState.set_default_directory (DefaultDir); } else { _state.appState.set_default_directory (get_home_directory ()); } _state.rt.set_session_config (session); } } else { _state.log.error << "Failed parsing session file: " << _state.sessionPath << endl; } } else if (!_state.quiet) { _state.log.info << "Session file: " << _state.sessionPath << " does not exist" << endl; result = False; } } return result; }