blob: 8d6770cd76c8b20c30149f9c5584570083eaa4f7 [file] [log] [blame]
njn36a20fa2005-06-03 03:08:39 +00001
2/*--------------------------------------------------------------------*/
3/*--- Printing libc stuff. pub_tool_libcprint.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj4d474d02008-02-11 11:34:59 +000010 Copyright (C) 2000-2008 Julian Seward
njn36a20fa2005-06-03 03:08:39 +000011 jseward@acm.org
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __PUB_TOOL_LIBCPRINT_H
32#define __PUB_TOOL_LIBCPRINT_H
33
bartfe101bf2008-03-17 18:57:03 +000034
35/* Enable compile-time format string checking by gcc if the macro
36 CHECK_FORMAT_STRINGS has been defined before this file has been included.
37 This feature is supported since at least gcc version 2.95.
38 For more information about the format attribute, see also
39 http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html.
40 */
41
42#if defined(__GNUC__) && defined(CHECK_FORMAT_STRINGS)
43#define PRINTF_CHECK(x, y) __attribute__((format(__printf__, x, y)))
44#else
45#define PRINTF_CHECK(x, y)
46#endif
47
48
njn36a20fa2005-06-03 03:08:39 +000049/* ---------------------------------------------------------------------
50 Basic printing
51 ------------------------------------------------------------------ */
52
53/* Note that they all output to the file descriptor given by the
54 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
55 * Hence no need for VG_(fprintf)().
56 */
bartfe101bf2008-03-17 18:57:03 +000057extern UInt VG_(printf) ( const HChar *format, ... ) PRINTF_CHECK(1, 2);
58extern UInt VG_(vprintf) ( const HChar *format, va_list vargs ) PRINTF_CHECK(1, 0);
59extern UInt VG_(sprintf) ( Char* buf, const HChar* format, ... ) PRINTF_CHECK(2, 3);
60extern UInt VG_(vsprintf) ( Char* buf, const HChar* format, va_list vargs ) PRINTF_CHECK(2, 0);
sewardj45f4e7c2005-09-27 19:20:21 +000061extern UInt VG_(snprintf) ( Char* buf, Int size,
bartfe101bf2008-03-17 18:57:03 +000062 const HChar *format, ... ) PRINTF_CHECK(3, 4);
sewardj45f4e7c2005-09-27 19:20:21 +000063extern UInt VG_(vsnprintf)( Char* buf, Int size,
bartfe101bf2008-03-17 18:57:03 +000064 const HChar *format, va_list vargs ) PRINTF_CHECK(3, 0);
njn36a20fa2005-06-03 03:08:39 +000065
njn7a5915e2005-07-17 16:12:59 +000066// Percentify n/m with d decimal places. Includes the '%' symbol at the end.
njn5eaff2f2005-09-25 19:11:45 +000067// Right justifies in 'buf'.
68extern void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, char buf[]);
njn856c54e2005-06-26 18:43:40 +000069
njn36a20fa2005-06-03 03:08:39 +000070/* ---------------------------------------------------------------------
71 Messages for the user
72 ------------------------------------------------------------------ */
73
njn3e114522005-06-11 03:31:09 +000074/* No, really. I _am_ that strange. */
75#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
76
njn36a20fa2005-06-03 03:08:39 +000077/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
78 Should be used for all user output. */
79
80typedef
81 enum { Vg_UserMsg, /* '?' == '=' */
82 Vg_DebugMsg, /* '?' == '-' */
83 Vg_DebugExtraMsg, /* '?' == '+' */
84 Vg_ClientMsg /* '?' == '*' */
85 }
86 VgMsgKind;
87
88/* Send a single-part message. Appends a newline. */
bartfe101bf2008-03-17 18:57:03 +000089extern UInt VG_(message) ( VgMsgKind kind, const HChar* format, ... ) PRINTF_CHECK(2, 3);
njn36a20fa2005-06-03 03:08:39 +000090
bartfe101bf2008-03-17 18:57:03 +000091extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs ) PRINTF_CHECK(2, 0);
njn36a20fa2005-06-03 03:08:39 +000092#endif // __PUB_TOOL_LIBCPRINT_H
93
94/*--------------------------------------------------------------------*/
95/*--- end ---*/
96/*--------------------------------------------------------------------*/