Mercurial > love-experiments
annotate src/common/Exception.cpp @ 1448:108ee2e81f65 default tip
Fix a case typo, imageData.h -> ImageData.h
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 18 Jan 2014 13:57:44 +0100 |
| parents | b7f097053d74 |
| children |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1096
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "Exception.h" | |
| 22 #include "common/config.h" | |
| 23 | |
| 24 #include <iostream> | |
| 25 | |
| 26 using namespace std; | |
| 27 | |
| 28 namespace love | |
| 29 { | |
| 30 | |
| 31 Exception::Exception(const char *fmt, ...) | |
| 32 { | |
| 33 va_list args; | |
| 34 int size_buffer = 256, size_out; | |
| 35 char *buffer; | |
| 36 while (true) | |
| 37 { | |
| 38 buffer = new char[size_buffer]; | |
| 39 memset(buffer, 0, size_buffer); | |
| 40 | |
| 41 va_start(args, fmt); | |
| 42 size_out = vsnprintf(buffer, size_buffer, fmt, args); | |
| 43 va_end(args); | |
| 44 | |
| 45 // see http://perfec.to/vsnprintf/pasprintf.c | |
| 46 // if size_out ... | |
| 47 // == -1 --> output was truncated | |
| 48 // == size_buffer --> output was truncated | |
| 49 // == size_buffer-1 --> ambiguous, /may/ have been truncated | |
| 50 // > size_buffer --> output was truncated, and size_out | |
| 51 // bytes would have been written | |
| 52 if (size_out == size_buffer || size_out == -1 || size_out == size_buffer-1) | |
| 53 size_buffer *= 2; | |
| 54 else if (size_out > size_buffer) | |
| 55 size_buffer = size_out + 2; // to avoid the ambiguous case | |
| 56 else | |
| 57 break; | |
| 58 | |
| 59 delete[] buffer; | |
| 60 } | |
| 61 message = std::string(buffer); | |
| 62 delete[] buffer; | |
| 63 } | |
| 64 | |
| 65 } |
