|
a/upmpd/upmpdutils.cxx |
|
b/upmpd/upmpdutils.cxx |
|
... |
|
... |
17 |
#include <unistd.h>
|
17 |
#include <unistd.h>
|
18 |
#include <fcntl.h>
|
18 |
#include <fcntl.h>
|
19 |
#include <sys/types.h>
|
19 |
#include <sys/types.h>
|
20 |
#include <sys/stat.h>
|
20 |
#include <sys/stat.h>
|
21 |
#include <math.h>
|
21 |
#include <math.h>
|
|
|
22 |
#include <pwd.h>
|
22 |
#include <regex.h>
|
23 |
#include <regex.h>
|
23 |
#include <errno.h>
|
24 |
#include <errno.h>
|
24 |
#include <string.h>
|
25 |
#include <string.h>
|
25 |
#ifndef O_STREAMING
|
26 |
#ifndef O_STREAMING
|
26 |
#define O_STREAMING 0
|
27 |
#define O_STREAMING 0
|
|
... |
|
... |
107 |
if (fd >= 0)
|
108 |
if (fd >= 0)
|
108 |
close(fd);
|
109 |
close(fd);
|
109 |
return ret;
|
110 |
return ret;
|
110 |
}
|
111 |
}
|
111 |
|
112 |
|
|
|
113 |
void path_catslash(string &s) {
|
|
|
114 |
if (s.empty() || s[s.length() - 1] != '/')
|
|
|
115 |
s += '/';
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
string path_cat(const string &s1, const string &s2) {
|
|
|
119 |
string res = s1;
|
|
|
120 |
path_catslash(res);
|
|
|
121 |
res += s2;
|
|
|
122 |
return res;
|
|
|
123 |
}
|
|
|
124 |
string path_home()
|
|
|
125 |
{
|
|
|
126 |
uid_t uid = getuid();
|
|
|
127 |
|
|
|
128 |
struct passwd *entry = getpwuid(uid);
|
|
|
129 |
if (entry == 0) {
|
|
|
130 |
const char *cp = getenv("HOME");
|
|
|
131 |
if (cp)
|
|
|
132 |
return cp;
|
|
|
133 |
else
|
|
|
134 |
return "/";
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
string homedir = entry->pw_dir;
|
|
|
138 |
path_catslash(homedir);
|
|
|
139 |
return homedir;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
string path_tildexpand(const string &s)
|
|
|
143 |
{
|
|
|
144 |
if (s.empty() || s[0] != '~')
|
|
|
145 |
return s;
|
|
|
146 |
string o = s;
|
|
|
147 |
if (s.length() == 1) {
|
|
|
148 |
o.replace(0, 1, path_home());
|
|
|
149 |
} else if (s[1] == '/') {
|
|
|
150 |
o.replace(0, 2, path_home());
|
|
|
151 |
} else {
|
|
|
152 |
string::size_type pos = s.find('/');
|
|
|
153 |
int l = (pos == string::npos) ? s.length() - 1 : pos - 1;
|
|
|
154 |
struct passwd *entry = getpwnam(s.substr(1, l).c_str());
|
|
|
155 |
if (entry)
|
|
|
156 |
o.replace(0, l+1, entry->pw_dir);
|
|
|
157 |
}
|
|
|
158 |
return o;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
void trimstring(string &s, const char *ws)
|
|
|
163 |
{
|
|
|
164 |
string::size_type pos = s.find_first_not_of(ws);
|
|
|
165 |
if (pos == string::npos) {
|
|
|
166 |
s.clear();
|
|
|
167 |
return;
|
|
|
168 |
}
|
|
|
169 |
s.replace(0, pos, string());
|
|
|
170 |
|
|
|
171 |
pos = s.find_last_not_of(ws);
|
|
|
172 |
if (pos != string::npos && pos != s.length()-1)
|
|
|
173 |
s.replace(pos+1, string::npos, string());
|
|
|
174 |
}
|
|
|
175 |
|
112 |
string xmlquote(const string& in)
|
176 |
string xmlquote(const string& in)
|
113 |
{
|
177 |
{
|
114 |
string out;
|
178 |
string out;
|
115 |
for (unsigned int i = 0; i < in.size(); i++) {
|
179 |
for (unsigned int i = 0; i < in.size(); i++) {
|
116 |
switch(in[i]) {
|
180 |
switch(in[i]) {
|