diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-05-31 16:21:54 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-05-31 16:21:54 -0400 |
commit | dff73d26f3a6c9d7011ad98a6752129a37625a10 (patch) | |
tree | 6fdf63be0e3331f098675bf694333672b699f7f1 /src/common/compat.c | |
parent | fc0842275de8f8ab43374df922907d97b4e60b58 (diff) | |
parent | b86c562d76c7b0cce25a3a9f46d5d66e2eef30ff (diff) | |
download | tor-dff73d26f3a6c9d7011ad98a6752129a37625a10.tar.gz tor-dff73d26f3a6c9d7011ad98a6752129a37625a10.zip |
Merge remote-tracking branch 'public/bug5089'
Conflicts:
src/test/test_util.c
Merge the unit tests; I added some when I did this branch against
0.2.2, and then the test format changed and master added more tests.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 59c7ca4c5a..093106120d 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1656,7 +1656,11 @@ get_user_homedir(const char *username) } #endif -/** Modify <b>fname</b> to contain the name of the directory */ +/** Modify <b>fname</b> 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 iteself. + * */ int get_parent_directory(char *fname) { @@ -1678,13 +1682,18 @@ get_parent_directory(char *fname) */ cp = fname + strlen(fname); at_end = 1; - while (--cp > fname) { + while (--cp >= fname) { int is_sep = (*cp == '/' #ifdef _WIN32 || *cp == '\\' #endif ); if (is_sep) { + if (cp == fname) { + /* This is the first separator in the file name; don't remove it! */ + cp[1] = '\0'; + return 0; + } *cp = '\0'; if (! at_end) return 0; |