|
Tor 0.4.9.8
|
Manipulate strings that contain filesystem paths. More...
#include "lib/fs/path.h"#include "lib/malloc/malloc.h"#include "lib/log/log.h"#include "lib/log/util_bug.h"#include "lib/container/smartlist.h"#include "lib/sandbox/sandbox.h"#include "lib/string/printf.h"#include "lib/string/util_string.h"#include "lib/string/compat_ctype.h"#include "lib/string/compat_string.h"#include "lib/fs/files.h"#include "lib/fs/dir.h"#include "lib/fs/userdb.h"#include <dirent.h>#include <glob.h>#include <errno.h>#include <string.h>Go to the source code of this file.
Functions | |
| char * | get_unquoted_path (const char *path) |
| char * | expand_filename (const char *filename) |
| int | path_is_relative (const char *filename) |
| void | clean_fname_for_stat (char *name) |
| int | get_parent_directory (char *fname) |
| static char * | alloc_getcwd (void) |
| char * | make_path_absolute (const char *fname) |
| static bool | is_glob_char (const char *pattern, int pos) |
| static bool | add_non_glob_path (const char *path, struct smartlist_t *result) |
| static struct smartlist_t * | get_glob_paths (const char *pattern, unglob_fn unglob, bool final) |
| struct smartlist_t * | tor_glob (const char *pattern) |
| bool | has_glob (const char *s) |
| static struct smartlist_t * | unglob_opened_files (const char *pattern, int prev_sep, int next_sep) |
| struct smartlist_t * | get_glob_opened_files (const char *pattern) |
Manipulate strings that contain filesystem paths.
Definition in file path.c.
|
static |
Adds path to result if it exists and is a file type we can handle. Returns false if path is a file type we cannot handle, returns true otherwise. Used on tor_glob for WIN32.
Definition at line 397 of file path.c.
Referenced by get_glob_paths().
|
static |
Return a newly allocated string containing the output of getcwd(). Return NULL on failure. (We can't just use getcwd() into a PATH_MAX buffer, since Hurd hasn't got a PATH_MAX.)
Definition at line 244 of file path.c.
Referenced by make_path_absolute().
| void clean_fname_for_stat | ( | char * | name | ) |
Clean up name so that we can use it in a call to "stat". On Unix, we do nothing. On Windows, we remove a trailing slash, unless the path is the root of a disk.
Definition at line 165 of file path.c.
Referenced by add_non_glob_path(), check_private_dir(), and file_status().
| char * expand_filename | ( | const char * | filename | ) |
Expand any homedir prefix on filename; return a newly allocated string.
Definition at line 85 of file path.c.
Referenced by find_torrc_filename(), get_data_directory(), and options_init_logs().
| struct smartlist_t * get_glob_opened_files | ( | const char * | pattern | ) |
|
static |
Auxiliary function used by get_glob_opened_files and WIN32 tor_glob. Returns a list of paths obtained from pattern using unglob to expand each path fragment. If final is true, the paths are the result of the glob expansion of pattern (implements tor_glob). Otherwise, the paths are the paths opened by glob while expanding pattern (implements get_glob_opened_files). Returns NULL on failure.
Definition at line 419 of file path.c.
Referenced by get_glob_opened_files(), get_glob_paths(), and tor_glob().
| int get_parent_directory | ( | char * | fname | ) |
Modify fname to contain the name of its parent directory. Doesn't actually examine the filesystem; does a purely syntactic modification.
The parent of the root director is considered to be itself.
Path separators are the forward slash (/) everywhere and additionally the backslash () on Win32.
Cuts off any number of trailing path separators but otherwise ignores them for purposes of finding the parent directory.
Returns 0 if a parent directory was successfully found, -1 otherwise (fname did not have any path separators or only had them at the end).
| char * get_unquoted_path | ( | const char * | path | ) |
| bool has_glob | ( | const char * | s | ) |
Returns true if s contains characters that can be globbed. Returns false otherwise.
Definition at line 668 of file path.c.
Referenced by unglob_opened_files().
|
inlinestatic |
Returns true if the character at position pos in pattern is considered a glob. Returns false otherwise. Takes escaping into account on systems where escaping globs is supported.
Definition at line 373 of file path.c.
Referenced by get_glob_paths(), and has_glob().
| char * make_path_absolute | ( | const char * | fname | ) |
Expand possibly relative path fname to an absolute path. Return a newly allocated string, which may be a duplicate of fname.
Definition at line 281 of file path.c.
Referenced by find_torrc_filename(), get_esc_cfile(), and warn_if_option_path_is_relative().
| int path_is_relative | ( | const char * | filename | ) |
Return true iff filename is a relative path.
Definition at line 146 of file path.c.
Referenced by warn_if_option_path_is_relative().
| struct smartlist_t * tor_glob | ( | const char * | pattern | ) |
Return a new list containing the paths that match the pattern pattern. Return NULL on error. On POSIX systems, errno is set by the glob function or is set to EPERM if glob tried to access a file not allowed by the seccomp sandbox.
Definition at line 598 of file path.c.
Referenced by unglob_opened_files().
|
static |
Expands globs in pattern for the path fragment between prev_sep and next_sep using tor_glob. Returns NULL on failure. Used by get_glob_opened_files. Implements unglob_fn, see its description for more details.
Definition at line 684 of file path.c.
Referenced by get_glob_opened_files().