Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 80 lines (69 sloc) 2.351 kB
4d4d90b @hzeller o More legalese
authored
1 // Folve - A fuse filesystem that convolves audio files on-the-fly.
2 //
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
3 // Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
1bce634 @hzeller o Remove some trailing whitespaces
authored
4 //
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
18 #include "util.h"
19
8268c37 @hzeller o Bubble up error messages in status server.
authored
20 #include <stdarg.h>
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
21 #include <stdio.h>
8268c37 @hzeller o Bubble up error messages in status server.
authored
22 #include <sys/time.h>
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
23 #include <syslog.h>
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
24
a9d3e53 @hzeller o Found a project name: "Folve". Some renamings because of that.
authored
25 double folve::CurrentTime() {
c1a03f2 @hzeller o Needed convenient sub-second resolution time. Added CurrentTime()
authored
26 struct timeval tv;
27 gettimeofday(&tv, NULL);
28 return tv.tv_sec + tv.tv_usec / 1e6;
29 }
8268c37 @hzeller o Bubble up error messages in status server.
authored
30
3e883b7 @hzeller o Match filters in sequence
authored
31 static void vAppendf(std::string *str, const char *format, va_list ap) {
8268c37 @hzeller o Bubble up error messages in status server.
authored
32 const size_t orig_len = str->length();
3e883b7 @hzeller o Match filters in sequence
authored
33 const size_t space = 1024; // there should be better ways to do this...
8268c37 @hzeller o Bubble up error messages in status server.
authored
34 str->resize(orig_len + space);
35 int written = vsnprintf((char*)str->data() + orig_len, space, format, ap);
36 str->resize(orig_len + written);
37 }
3e883b7 @hzeller o Match filters in sequence
authored
38
39 void folve::Appendf(std::string *str, const char *format, ...) {
40 va_list ap;
41 va_start(ap, format);
42 vAppendf(str, format, ap);
43 va_end(ap);
44 }
45
46 std::string folve::StringPrintf(const char *format, ...) {
47 std::string result;
48 va_list ap;
49 va_start(ap, format);
50 vAppendf(&result, format, ap);
51 va_end(ap);
52 return result;
53 }
ac40d85 @hzeller o Make sure we match the alphabetically next file with
authored
54
7689c9a @hzeller o preparation to extract classes from folve-filesystem into their
authored
55 static bool global_debug_log = false;
56 void folve::EnableDebugLog(bool b) {
57 if (b != global_debug_log) {
58 syslog(LOG_INFO, "Switch debug mode %s.", b ? "on" : "off");
59 global_debug_log = b;
60 }
61 }
62
63 bool folve::IsDebugLogEnabled() {
64 return global_debug_log;
65 }
66
67 void folve::DLogf(const char *format, ...) {
68 if (!global_debug_log) return;
69 va_list ap;
70 va_start(ap, format);
71 vsyslog(LOG_DEBUG, format, ap);
72 va_end(ap);
73 }
74
ac40d85 @hzeller o Make sure we match the alphabetically next file with
authored
75 bool folve::HasSuffix(const std::string &str, const std::string &suffix) {
76 if (str.length() < suffix.length()) return false;
77 return str.compare(str.length() - suffix.length(),
78 suffix.length(), suffix) == 0;
79 }
Something went wrong with that request. Please try again.