summaryrefslogtreecommitdiffabout
path: root/include
authorMichael Krelin <hacker@klever.net>2005-04-25 16:27:12 (UTC)
committer Michael Krelin <hacker@klever.net>2005-04-25 16:27:12 (UTC)
commita74c677c09774c02d3bc347525fb071f25d25697 (patch) (unidiff)
tree8f28192b802047486998460b0894e90fde480fd3 /include
parenta83335d1c67d37100a018e8ee4fd6c0ff77ac380 (diff)
downloadkonforka-a74c677c09774c02d3bc347525fb071f25d25697.zip
konforka-a74c677c09774c02d3bc347525fb071f25d25697.tar.gz
konforka-a74c677c09774c02d3bc347525fb071f25d25697.tar.bz2
1. bumped version to 0.0.1
2. added utility functions extracted from sitecing
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am1
-rw-r--r--include/konforka/util.h103
2 files changed, 104 insertions, 0 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 3e043d3..5fbf85e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@ endif
6 6
7nobase_include_HEADERS = \ 7nobase_include_HEADERS = \
8 konforka/exception.h \ 8 konforka/exception.h \
9 konforka/util.h \
9 konforka/basic_wrapper.h konforka/responsible_wrapper.h \ 10 konforka/basic_wrapper.h konforka/responsible_wrapper.h \
10 konforka/resource_pile.h \ 11 konforka/resource_pile.h \
11 konforka/pointer_map.h \ 12 konforka/pointer_map.h \
diff --git a/include/konforka/util.h b/include/konforka/util.h
new file mode 100644
index 0000000..c06edd9
--- a/dev/null
+++ b/include/konforka/util.h
@@ -0,0 +1,103 @@
1#ifndef __KONFORKA_UTIL_H
2#define __KONFORKA_UTIL_H
3
4#include <sys/types.h>
5#include <string>
6#include <konforka/exception.h>
7
8/**
9 * @file
10 * @brief miscellaneous utility stuff.
11 */
12
13/**
14 * @brief The main konforka namespace.
15 */
16namespace konforka {
17 using std::string;
18
19 class restricted_sequence_error : public konforka::exception {
20 public:
21 restricted_sequence_error(const string& fi,const string& fu,int l,const string& w)
22 : konforka::exception(fi,fu,l,w) { }
23 };
24
25 /**
26 * normalize_path options enumeration.
27 * @see normalize_path()
28 */
29 enum normalize_path_options {
30 /**
31 * Restrict the /../ sequence.
32 */
33 restrict_dotdot = 1,
34 /**
35 * Strip out the leading slash.
36 */
37 strip_leading_slash = 2,
38 /**
39 * Strip out the trailing slash.
40 */
41 strip_trailing_slash = 4
42 };
43
44 /**
45 * Normalize pathname by stripping duplicate slashes, etc.
46 * @param p the pathname.
47 * @param o options.
48 * @return the normalized path.
49 * @see normalize_path_options
50 * @todo TODO: document exceptions.
51 */
52 string normalize_path(const string& p,int o=(restrict_dotdot|strip_trailing_slash));
53
54 /**
55 * Extract the directory part of the filename.
56 * @param p the pathname.
57 * @return the directory part.
58 */
59 string dir_name(const string& p);
60
61 class beyond_root_error : public konforka::exception {
62 public:
63 beyond_root_error(const string& fi,const string& fu,int l,const string& w)
64 : konforka::exception(fi,fu,l,w) { }
65 };
66
67 /**
68 * combine_path options enumeration.
69 * @see combine_path()
70 */
71 enum combine_path_options {
72 /**
73 * The origin is file. Otherwise it is directory.
74 */
75 origin_is_file = 1,
76 /**
77 * Fail if we've gone up beyond root.
78 */
79 fail_beyond_root = 2
80 };
81
82 /**
83 * Combine path with the relative path.
84 * @param orig the origin.
85 * @param rel relative path to combine with.
86 * @param o options.
87 * @return the paths combined.
88 * @see combine_path_options
89 * @todo TODO: document exceptions.
90 */
91 string combine_path(const string& orig,const string& rel,int o=origin_is_file);
92
93 /**
94 * Create directory and parent directories if needed.
95 * @param p the pathname.
96 * @param m mode value for the newly created directories.
97 */
98 void make_path(const string& p,mode_t m);
99
100}
101
102 /* vim:set ft=cpp: */
103#endif /* __KONFORKA_UTIL_H */