Switch to unified view

a/src/utils/pathut.cpp b/src/utils/pathut.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.1 2004-12-10 18:13:14 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.2 2004-12-14 17:54:16 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
4
5
#ifndef TEST_PATHUT
5
#ifndef TEST_PATHUT
6
6
7
#include <pwd.h>
7
#include <pwd.h>
...
...
29
    father.erase(slp);
29
    father.erase(slp);
30
    path_catslash(father);
30
    path_catslash(father);
31
    return father;
31
    return father;
32
}
32
}
33
33
34
std::string path_getsimple(const std::string &s) {
35
    std::string simple = s;
36
37
    if (simple.empty())
38
  return simple;
39
40
    std::string::size_type slp = simple.rfind('/');
41
    if (slp == std::string::npos)
42
  return simple;
43
44
    simple.erase(0, slp+1);
45
    return simple;
46
}
47
34
std::string path_home()
48
std::string path_home()
35
{
49
{
36
    uid_t uid = getuid();
50
    uid_t uid = getuid();
37
51
38
    struct passwd *entry = getpwuid(uid);
52
    struct passwd *entry = getpwuid(uid);
...
...
51
65
52
#include "pathut.h"
66
#include "pathut.h"
53
67
54
const char *tstvec[] = {"", "/", "/dir", "/dir/", "/dir1/dir2",
68
const char *tstvec[] = {"", "/", "/dir", "/dir/", "/dir1/dir2",
55
             "/dir1/dir2",
69
             "/dir1/dir2",
56
             "./dir", "./dir1/", "dir", "../dir"};
70
            "./dir", "./dir1/", "dir", "../dir", "/dir/toto.c",
71
          "/dir/.c",
72
};
57
73
58
int main(int argc, const char **argv)
74
int main(int argc, const char **argv)
59
{
75
{
60
76
61
    for (int i = 0;i < sizeof(tstvec) / sizeof(char *); i++) {
77
    for (int i = 0;i < sizeof(tstvec) / sizeof(char *); i++) {
62
    cout << tstvec[i] << " -> " << path_getfather(tstvec[i]) << endl;
78
    cout << tstvec[i] << " FATHER " << path_getfather(tstvec[i]) << endl;
79
    }
80
    for (int i = 0;i < sizeof(tstvec) / sizeof(char *); i++) {
81
  cout << tstvec[i] << " SIMPLE " << path_getsimple(tstvec[i]) << endl;
63
    }
82
    }
64
    return 0;
83
    return 0;
65
}
84
}
66
85
67
#endif // TEST_PATHUT
86
#endif // TEST_PATHUT