1 /* cclive
2 * Copyright (C) 2010-2013 Toni Gundogdu <legatvs@gmail.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <ccinternal>
19
20 #include <stdexcept>
21 #include <cstdarg>
22 #include <cerrno>
23
24 #include <boost/filesystem.hpp>
25
26 #include <ccquvi>
27 #include <ccutil>
28 #include <cclog>
29
30 namespace cc
31 {
32
33 namespace fs = boost::filesystem;
34 namespace io = boost::iostreams;
35
36 io::filtering_ostream log;
37
_open()38 void flushable_file_sink::_open()
39 {
40 _fpath = fs::system_complete(fs::path(_fpath)).string();
41 _f.open(_fpath.c_str(), _mode);
42 if (_f.fail())
43 {
44 std::string s = _fpath + ": ";
45
46 if (errno)
47 s += cc::perror();
48 else
49 s += "unknown file open error";
50
51 throw std::runtime_error(s);
52 }
53 }
54
_debug(const std::string & fn,const std::string & func,const int ln,const char * fmt,...)55 void _debug(const std::string& fn, const std::string& func,
56 const int ln, const char *fmt, ...)
57 {
58 va_list args;
59 va_start(args, fmt);
60 fprintf(stderr, "[%s:%d] ", fn.c_str(), ln);
61 vfprintf(stderr, fmt, args);
62 fprintf(stderr, "\n");
63 va_end(args);
64 }
65
66 } // namspace cclive
67
68 // vim: set ts=2 sw=2 tw=72 expandtab:
69