1 /* cclive
2  * Copyright (C) 2010-2011  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 <iostream>
21 #include <climits>
22 #include <cstring>
23 #include <cerrno>
24 
25 #include <ccquvi>
26 #include <ccutil>
27 
28 namespace cc
29 {
30 
perror(const std::string & p)31 std::string perror(const std::string& p/*=""*/)
32 {
33 #if defined (HAVE_STRERROR) || defined (HAVE_STRERROR_R)
34   std::string s;
35 #ifdef HAVE_STRERROR_R
36   char buf[256];
37   s = strerror_r(errno, buf, sizeof(buf));
38 #else // HAVE_STRERROR_R
39   s = strerror(errno);
40 #endif // HAVE_STRERROR_R
41   return s;
42 #else // HAVE_STRERROR || HAVE_STRERROR_R
43   perror(p.c_str()); // No strerror or strerror_r
44 #endif // HAVE_STRERROR || HAVE_STRERROR_R
45 }
46 
47 } // namspace cclive
48 
49 // vim: set ts=2 sw=2 tw=72 expandtab:
50