| | 227 | |
|---|
| | 228 | #ifdef _DEBUG |
|---|
| | 229 | void |
|---|
| | 230 | Stream::debug(const char* pFormat, ...) { |
|---|
| | 231 | if (!mDebugFlag) |
|---|
| | 232 | return; |
|---|
| | 233 | /* Guess we need no more than 100 bytes. */ |
|---|
| | 234 | int n, size = 100; |
|---|
| | 235 | char *p, *np; |
|---|
| | 236 | va_list ap; |
|---|
| | 237 | |
|---|
| | 238 | if ((p = (char*)malloc (size)) == NULL) |
|---|
| | 239 | return; |
|---|
| | 240 | |
|---|
| | 241 | while (1) { |
|---|
| | 242 | /* Try to print in the allocated space. */ |
|---|
| | 243 | va_start(ap, pFormat); |
|---|
| | 244 | n = vsnprintf (p, size, pFormat, ap); |
|---|
| | 245 | va_end(ap); |
|---|
| | 246 | /* If that worked, return the string. */ |
|---|
| | 247 | if (n > -1 && n < size) |
|---|
| | 248 | break; |
|---|
| | 249 | /* Else try again with more space. */ |
|---|
| | 250 | if (n > -1) /* glibc 2.1 */ |
|---|
| | 251 | size = n+1; /* precisely what is needed */ |
|---|
| | 252 | else /* glibc 2.0 */ |
|---|
| | 253 | size *= 2; /* twice the old size */ |
|---|
| | 254 | if ((np = (char*)realloc (p, size)) == NULL) { |
|---|
| | 255 | free(p); |
|---|
| | 256 | return; |
|---|
| | 257 | } else { |
|---|
| | 258 | p = np; |
|---|
| | 259 | } |
|---|
| | 260 | } |
|---|
| | 261 | std::cerr << p << std::endl; |
|---|
| | 262 | free(p); |
|---|
| | 263 | }; |
|---|
| | 264 | #endif |
|---|