1 /* libClunk - cross-platform 3D audio API built on top SDL library
2 * Copyright (C) 2007-2008 Netive Media Group
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "clunk_ex.h"
20 #include <errno.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #if defined _MSC_VER
25 # ifndef snprintf
26 # define snprintf _snprintf
27 # endif
28 #endif
29
add_message(const char * file,int line)30 void clunk::Exception::add_message(const char *file, int line) {
31 char buf[1024];
32 snprintf(buf, sizeof(buf), "[%s:%d] ", file, line);
33 message += buf;
34 }
35
add_message(const std::string & msg)36 void clunk::Exception::add_message(const std::string &msg) {
37 message += msg;
38 message += ' ';
39 }
40
add_custom_message()41 void clunk::IOException::add_custom_message() {
42 char buf[1024];
43 memset(buf, 0, sizeof(buf));
44
45 #ifdef _MSC_VER
46 strncpy(buf, _strerror(NULL), sizeof(buf));
47 #else
48 strncpy(buf, strerror(errno), sizeof(buf));
49 // if (strerror_r(errno, buf, sizeof(buf)-1) != 0) perror("strerror");
50 #endif
51 add_message(buf);
52 }
53
54