Path: blob/main/sys/contrib/openzfs/lib/libspl/kmem.c
96339 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.23* Copyright (c) 2012, 2018 by Delphix. All rights reserved.24* Copyright (c) 2016 Actifio, Inc. All rights reserved.25* Copyright (c) 2025, Klara, Inc.26*/2728#include <sys/kmem.h>2930char *31kmem_vasprintf(const char *fmt, va_list adx)32{33char *buf = NULL;34va_list adx_copy;3536va_copy(adx_copy, adx);37VERIFY(vasprintf(&buf, fmt, adx_copy) != -1);38va_end(adx_copy);3940return (buf);41}4243char *44kmem_asprintf(const char *fmt, ...)45{46char *buf = NULL;47va_list adx;4849va_start(adx, fmt);50VERIFY(vasprintf(&buf, fmt, adx) != -1);51va_end(adx);5253return (buf);54}5556/*57* kmem_scnprintf() will return the number of characters that it would have58* printed whenever it is limited by value of the size variable, rather than59* the number of characters that it did print. This can cause misbehavior on60* subsequent uses of the return value, so we define a safe version that will61* return the number of characters actually printed, minus the NULL format62* character. Subsequent use of this by the safe string functions is safe63* whether it is snprintf(), strlcat() or strlcpy().64*/65int66kmem_scnprintf(char *restrict str, size_t size, const char *restrict fmt, ...)67{68int n;69va_list ap;7071/* Make the 0 case a no-op so that we do not return -1 */72if (size == 0)73return (0);7475va_start(ap, fmt);76n = vsnprintf(str, size, fmt, ap);77va_end(ap);7879if (n >= size)80n = size - 1;8182return (n);83}8485fstrans_cookie_t86spl_fstrans_mark(void)87{88return ((fstrans_cookie_t)0);89}9091void92spl_fstrans_unmark(fstrans_cookie_t cookie)93{94(void) cookie;95}9697int98kmem_cache_reap_active(void)99{100return (0);101}102103104