MySQL 8.0.40
Source Code Documentation
ut.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file ut/ut.h
29 Various utilities
30
31 Created 1/20/1994 Heikki Tuuri
32 ***********************************************************************/
33
34/** NOTE: The functions in this file should only use functions from
35other files in library. The code in this file is used to make a library for
36external tools. */
37
38#ifndef ut_ut_h
39#define ut_ut_h
40
41#include "univ.i"
42/** Prints the contents of a memory buffer in hex and ascii. */
43void ut_print_buf(FILE *file, /*!< in: file where to print */
44 const void *buf, /*!< in: memory buffer */
45 ulint len); /*!< in: length of the buffer */
46
47/** Prints a timestamp to a file. */
48void ut_print_timestamp(FILE *file) /*!< in: file where to print */
50/** Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
51void ut_sprintf_timestamp(char *buf); /*!< in: buffer where to sprintf */
52
53/** Prints the contents of a memory buffer in hex.
54@param[in,out] o Output stream
55@param[in] buf Memory buffer
56@param[in] len Length of the buffer */
57void ut_print_buf_hex(std::ostream &o, const void *buf, ulint len);
58
59/** Prints the contents of a memory buffer in hex and ascii.
60@param[in,out] o Output stream
61@param[in] buf Memory buffer
62@param[in] len Length of the buffer */
63void ut_print_buf(std::ostream &o, const void *buf, ulint len);
64
65/** Like ut_strlcpy, but if src doesn't fit in dst completely, copies the last
66 (size - 1) bytes of src, not the first.
67 @return strlen(src) */
68ulint ut_strlcpy_rev(char *dst, /*!< in: destination buffer */
69 const char *src, /*!< in: source buffer */
70 ulint size); /*!< in: size of destination buffer */
71
73 PrintBuffer(const void *buf, ulint len) : m_buf(buf), m_len(len) {}
74
75 std::ostream &print(std::ostream &out) const {
76 if (m_buf != nullptr) {
78 }
79 return (out);
80 }
81
82 private:
83 const void *m_buf;
85};
86
87inline std::ostream &operator<<(std::ostream &out, const PrintBuffer &obj) {
88 return (obj.print(out));
89}
90
91#endif
Definition: buf0block_hint.cc:30
const std::string FILE("FILE")
Definition: os0file.h:86
Definition: ut.h:72
const void * m_buf
Definition: ut.h:83
std::ostream & print(std::ostream &out) const
Definition: ut.h:75
ulint m_len
Definition: ut.h:84
PrintBuffer(const void *buf, ulint len)
Definition: ut.h:73
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:267
unsigned long int ulint
Definition: univ.i:406
void ut_sprintf_timestamp(char *buf)
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL.
Definition: ut.cc:136
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:47
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:78
void ut_print_timestamp(FILE *file) UNIV_COLD
Prints a timestamp to a file.
Definition: ut.cc:109
std::ostream & operator<<(std::ostream &out, const PrintBuffer &obj)
Definition: ut.h:87
ulint ut_strlcpy_rev(char *dst, const char *src, ulint size)
Like ut_strlcpy, but if src doesn't fit in dst completely, copies the last (size - 1) bytes of src,...
Definition: ut.cc:163