MySQL 8.3.0
Source Code Documentation
ut.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2023, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
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
34other files in library. The code in this file is used to make a library for
35external 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. */
42void 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. */
47void ut_print_timestamp(FILE *file) /*!< in: file where to print */
49/** Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL. */
50void ut_sprintf_timestamp(char *buf); /*!< in: buffer where to sprintf */
51
52/** Prints the contents of a memory buffer in hex.
53@param[in,out] o Output stream
54@param[in] buf Memory buffer
55@param[in] len Length of the buffer */
56void ut_print_buf_hex(std::ostream &o, const void *buf, ulint len);
57
58/** Prints the contents of a memory buffer in hex and ascii.
59@param[in,out] o Output stream
60@param[in] buf Memory buffer
61@param[in] len Length of the buffer */
62void ut_print_buf(std::ostream &o, const void *buf, ulint len);
63
64/** Like ut_strlcpy, but if src doesn't fit in dst completely, copies the last
65 (size - 1) bytes of src, not the first.
66 @return strlen(src) */
67ulint ut_strlcpy_rev(char *dst, /*!< in: destination buffer */
68 const char *src, /*!< in: source buffer */
69 ulint size); /*!< in: size of destination buffer */
70
72 PrintBuffer(const void *buf, ulint len) : m_buf(buf), m_len(len) {}
73
74 std::ostream &print(std::ostream &out) const {
75 if (m_buf != nullptr) {
77 }
78 return (out);
79 }
80
81 private:
82 const void *m_buf;
84};
85
86inline std::ostream &operator<<(std::ostream &out, const PrintBuffer &obj) {
87 return (obj.print(out));
88}
89
90#endif
Definition: buf0block_hint.cc:29
const std::string FILE("FILE")
Definition: os0file.h:88
Definition: ut.h:71
const void * m_buf
Definition: ut.h:82
std::ostream & print(std::ostream &out) const
Definition: ut.h:74
ulint m_len
Definition: ut.h:83
PrintBuffer(const void *buf, ulint len)
Definition: ut.h:72
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:266
unsigned long int ulint
Definition: univ.i:405
void ut_sprintf_timestamp(char *buf)
Sprintfs a timestamp to a buffer, 13..14 chars plus terminating NUL.
Definition: ut.cc:135
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:46
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:77
void ut_print_timestamp(FILE *file) UNIV_COLD
Prints a timestamp to a file.
Definition: ut.cc:108
std::ostream & operator<<(std::ostream &out, const PrintBuffer &obj)
Definition: ut.h:86
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:162