1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2020, Huawei Technologies Co., Ltd
4 */
5
6 #include <compiler.h>
7 #include <printk.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
sprintf(char * str,const char * fmt,...)11 int sprintf(char *str, const char *fmt, ...)
12 {
13 int retval;
14 va_list ap;
15
16 va_start(ap, fmt);
17 retval = __vsprintf(str, fmt, ap);
18 va_end(ap);
19
20 return retval;
21 }
22
__sprintf_chk(char * str,int flag __unused,size_t slen,const char * fmt,...)23 int __sprintf_chk(char *str, int flag __unused, size_t slen,
24 const char *fmt, ...)
25 {
26 int retval;
27 va_list ap;
28
29 if (slen == 0)
30 abort();
31
32 va_start(ap, fmt);
33 retval = __vsnprintf(str, slen, fmt, ap, false);
34 va_end(ap);
35
36 if (retval > 0 && (size_t)retval >= slen)
37 abort();
38
39 return retval;
40 }
41