]>
Dogcows Code - chaz/yoink/blob - dprintf.cpp
b0e05c6b7097bd785c3a55c996bb0d383fba3dc0
1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
10 // Feb 2007: Rewritten in terms of platform-specific fixes to the
11 // buffer-overflow problem. Using native functions for this has the added
12 // benefit of giving access to other features of the C-runtime such as Unicode
15 ////////////////////////////////////////////////////////////////////////////////
17 #include "dprintf.hpp"
24 ////////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////////
31 int vdprintf(std::string
& formatted
, const char* format
, va_list args
)
36 for(int buffer_length
= 256; ; buffer_length
*=2)
38 buffer
= (char*)malloc(buffer_length
);
39 if (!buffer
) return -1;
40 length
= _vsnprintf(buffer
, buffer_length
-1, format
, args
);
44 formatted
+= std::string(buffer
);
53 int length
= vasprintf(&buffer
, format
, args
);
54 if (!buffer
) return -1;
56 formatted
+= std::string(buffer
);
62 int dprintf(std::string
& formatted
, const char* format
, ...)
65 va_start(args
, format
);
66 int result
= vdprintf(formatted
, format
, args
);
71 std::string
vdformat(const char* format
, va_list args
) throw(std::invalid_argument
)
73 std::string formatted
;
74 int length
= vdprintf(formatted
, format
, args
);
75 if (length
< 0) throw std::invalid_argument("dprintf");
79 std::string
dformat(const char* format
, ...) throw(std::invalid_argument
)
81 std::string formatted
;
83 va_start(args
, format
);
84 int length
= vdprintf(formatted
, format
, args
);
86 if (length
< 0) throw std::invalid_argument("dprintf");
90 ////////////////////////////////////////////////////////////////////////////////
92 } // end namespace stlplus
This page took 0.040565 seconds and 3 git commands to generate.