MySQL  8.0.20
Source Code Documentation
ut0mem.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1994, 2018, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/ut0mem.h
28  Memory primitives
29 
30  Created 5/30/1994 Heikki Tuuri
31  ************************************************************************/
32 
33 #ifndef ut0mem_h
34 #define ut0mem_h
35 
36 #include "univ.i"
37 #ifndef UNIV_HOTBACKUP
38 #include "os0event.h"
39 #include "ut0mutex.h"
40 #endif /* !UNIV_HOTBACKUP */
41 
42 /** Wrapper for memcpy(3). Copy memory area when the source and
43 target are not overlapping.
44 @param[in,out] dest copy to
45 @param[in] src copy from
46 @param[in] n number of bytes to copy
47 @return dest */
48 UNIV_INLINE
49 void *ut_memcpy(void *dest, const void *src, ulint n);
50 
51 /** Wrapper for memmove(3). Copy memory area when the source and
52 target are overlapping.
53 @param[in,out] dest Move to
54 @param[in] src Move from
55 @param[in] n number of bytes to move
56 @return dest */
57 UNIV_INLINE
58 void *ut_memmove(void *dest, const void *src, ulint n);
59 
60 /** Wrapper for memcmp(3). Compare memory areas.
61 @param[in] str1 first memory block to compare
62 @param[in] str2 second memory block to compare
63 @param[in] n number of bytes to compare
64 @return negative, 0, or positive if str1 is smaller, equal,
65  or greater than str2, respectively. */
66 UNIV_INLINE
67 int ut_memcmp(const void *str1, const void *str2, ulint n);
68 
69 /** Wrapper for strcpy(3). Copy a NUL-terminated string.
70 @param[in,out] dest Destination to copy to
71 @param[in] src Source to copy from
72 @return dest */
73 UNIV_INLINE
74 char *ut_strcpy(char *dest, const char *src);
75 
76 /** Wrapper for strlen(3). Determine the length of a NUL-terminated string.
77 @param[in] str string
78 @return length of the string in bytes, excluding the terminating NUL */
79 UNIV_INLINE
80 ulint ut_strlen(const char *str);
81 
82 /** Wrapper for strcmp(3). Compare NUL-terminated strings.
83 @param[in] str1 first string to compare
84 @param[in] str2 second string to compare
85 @return negative, 0, or positive if str1 is smaller, equal,
86  or greater than str2, respectively. */
87 UNIV_INLINE
88 int ut_strcmp(const char *str1, const char *str2);
89 
90 /** Copies up to size - 1 characters from the NUL-terminated string src to
91  dst, NUL-terminating the result. Returns strlen(src), so truncation
92  occurred if the return value >= size.
93  @return strlen(src) */
94 ulint ut_strlcpy(char *dst, /*!< in: destination buffer */
95  const char *src, /*!< in: source buffer */
96  ulint size); /*!< in: size of destination buffer */
97 
98 /********************************************************************
99 Concatenate 3 strings.*/
100 char *ut_str3cat(
101  /* out, own: concatenated string, must be
102  freed with ut_free() */
103  const char *s1, /* in: string 1 */
104  const char *s2, /* in: string 2 */
105  const char *s3); /* in: string 3 */
106 
107 /** Converts a raw binary data to a NUL-terminated hex string. The output is
108 truncated if there is not enough space in "hex", make sure "hex_size" is at
109 least (2 * raw_size + 1) if you do not want this to happen. Returns the actual
110 number of characters written to "hex" (including the NUL).
111 @param[in] raw raw data
112 @param[in] raw_size "raw" length in bytes
113 @param[out] hex hex string
114 @param[in] hex_size "hex" size in bytes
115 @return number of chars written */
116 UNIV_INLINE
117 ulint ut_raw_to_hex(const void *raw, ulint raw_size, char *hex, ulint hex_size);
118 
119 /** Adds single quotes to the start and end of string and escapes any quotes by
120 doubling them. Returns the number of bytes that were written to "buf"
121 (including the terminating NUL). If buf_size is too small then the trailing
122 bytes from "str" are discarded.
123 @param[in] str string
124 @param[in] str_len string length in bytes
125 @param[out] buf output buffer
126 @param[in] buf_size output buffer size in bytes
127 @return number of bytes that were written */
128 UNIV_INLINE
129 ulint ut_str_sql_format(const char *str, ulint str_len, char *buf,
130  ulint buf_size);
131 
132 #include "ut0mem.ic"
133 
134 #endif
char * ut_str3cat(const char *s1, const char *s2, const char *s3)
Definition: ut0mem.cc:60
UNIV_INLINE void * ut_memmove(void *dest, const void *src, ulint n)
Wrapper for memmove(3).
UNIV_INLINE ulint ut_str_sql_format(const char *str, ulint str_len, char *buf, ulint buf_size)
Adds single quotes to the start and end of string and escapes any quotes by doubling them...
Policy based mutexes.
int n
Definition: xcom_base.c:425
UNIV_INLINE void * ut_memcpy(void *dest, const void *src, ulint n)
Wrapper for memcpy(3).
The interface to the operating system condition variables.
UNIV_INLINE char * ut_strcpy(char *dest, const char *src)
Wrapper for strcpy(3).
UNIV_INLINE ulint ut_raw_to_hex(const void *raw, ulint raw_size, char *hex, ulint hex_size)
Converts a raw binary data to a NUL-terminated hex string.
UNIV_INLINE int ut_memcmp(const void *str1, const void *str2, ulint n)
Wrapper for memcmp(3).
ulint ut_strlcpy(char *dst, const char *src, ulint size)
Copies up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the resul...
Definition: ut0mem.cc:42
UNIV_INLINE int ut_strcmp(const char *str1, const char *str2)
Wrapper for strcmp(3).
UNIV_INLINE ulint ut_strlen(const char *str)
Wrapper for strlen(3).