MySQL  8.0.12
Source Code Documentation
ut.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 1994, 2018, Oracle and/or its affiliates. All Rights Reserved.
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24  The lines above are intentionally left blank
25 */
26 
27 /** @file ut/ut.h
28  Various utilities
29 
30  Created 1/20/1994 Heikki Tuuri
31  ***********************************************************************/
32 
33 /** NOTE: The functions in this file should only use functions from
34 other files in library. The code in this file is used to make a library for
35 external tools. */
36 
37 #ifndef ut_ut_h
38 #define ut_ut_h
39 
40 #include "univ.i"
41 /** Prints the contents of a memory buffer in hex and ascii. */
42 void ut_print_buf(FILE *file, /*!< in: file where to print */
43  const void *buf, /*!< in: memory buffer */
44  ulint len); /*!< in: length of the buffer */
45 
46 /** Prints a timestamp to a file. */
47 void ut_print_timestamp(FILE *file) /*!< in: file where to print */
48  UNIV_COLD;
49 /** Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
50 void ut_sprintf_timestamp(char *buf); /*!< in: buffer where to sprintf */
51 /** Prints the contents of a memory buffer in hex. */
52 void ut_print_buf_hex(std::ostream &o, /*!< in/out: output stream */
53  const void *buf, /*!< in: memory buffer */
54  ulint len); /*!< in: length of the buffer */
55 /** Prints the contents of a memory buffer in hex and ascii. */
56 void ut_print_buf(std::ostream &o, /*!< in/out: output stream */
57  const void *buf, /*!< in: memory buffer */
58  ulint len); /*!< in: length of the buffer */
59 /** Like ut_strlcpy, but if src doesn't fit in dst completely, copies the last
60  (size - 1) bytes of src, not the first.
61  @return strlen(src) */
62 ulint ut_strlcpy_rev(char *dst, /*!< in: destination buffer */
63  const char *src, /*!< in: source buffer */
64  ulint size); /*!< in: size of destination buffer */
65 
66 struct PrintBuffer {
67  PrintBuffer(const void *buf, ulint len) : m_buf(buf), m_len(len) {}
68 
69  std::ostream &print(std::ostream &out) const {
70  if (m_buf != nullptr) {
71  ut_print_buf(out, m_buf, m_len);
72  }
73  return (out);
74  }
75 
76  private:
77  const void *m_buf;
78  ulint m_len;
79 };
80 
81 inline std::ostream &operator<<(std::ostream &out, const PrintBuffer &obj) {
82  return (obj.print(out));
83 }
84 
85 #endif
ulint ut_strlcpy_rev(char *dst, const char *src, ulint size)
Like ut_strlcpy, but if src doesn&#39;t fit in dst completely, copies the last (size - 1) bytes of src...
Definition: ut.cc:168
PrintBuffer(const void *buf, ulint len)
Definition: ut.h:67
void ut_sprintf_timestamp(char *buf)
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL.
Definition: ut.cc:141
ulint m_len
Definition: ut.h:78
std::ostream & operator<<(std::ostream &out, const PrintBuffer &obj)
Definition: ut.h:81
unsigned int len
Definition: dbug_analyze.cc:216
Definition: ut.h:66
void ut_print_buf(FILE *file, const void *buf, ulint len)
NOTE: The functions in this file should only use functions from other files in library.
Definition: ut.cc:45
std::ostream & print(std::ostream &out) const
Definition: ut.h:69
void ut_print_timestamp(FILE *file) UNIV_COLD
Prints a timestamp to a file.
Definition: ut.cc:114
void ut_print_buf_hex(std::ostream &o, const void *buf, ulint len)
Prints the contents of a memory buffer in hex.
Definition: ut.cc:73
const void * m_buf
Definition: ut.h:77