xref: /optee_os/lib/libutils/isoc/snprintf.c (revision fe3ccf2450fb11c10c334a0c22de79fe8d2591a5)
1b0104773SPascal Brand /*
2*fe3ccf24SJerome Forissier  * Copyright (c) 2015, Linaro Limited
3*fe3ccf24SJerome Forissier  * All rights reserved.
4b0104773SPascal Brand  *
5b0104773SPascal Brand  * Redistribution and use in source and binary forms, with or without
6*fe3ccf24SJerome Forissier  * modification, are permitted provided that the following conditions are met:
7b0104773SPascal Brand  *
8*fe3ccf24SJerome Forissier  * 1. Redistributions of source code must retain the above copyright notice,
9*fe3ccf24SJerome Forissier  * this list of conditions and the following disclaimer.
10*fe3ccf24SJerome Forissier  *
11*fe3ccf24SJerome Forissier  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*fe3ccf24SJerome Forissier  * this list of conditions and the following disclaimer in the documentation
13*fe3ccf24SJerome Forissier  * and/or other materials provided with the distribution.
14*fe3ccf24SJerome Forissier  *
15*fe3ccf24SJerome Forissier  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16*fe3ccf24SJerome Forissier  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17b0104773SPascal Brand  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*fe3ccf24SJerome Forissier  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19*fe3ccf24SJerome Forissier  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*fe3ccf24SJerome Forissier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*fe3ccf24SJerome Forissier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*fe3ccf24SJerome Forissier  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*fe3ccf24SJerome Forissier  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*fe3ccf24SJerome Forissier  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*fe3ccf24SJerome Forissier  * POSSIBILITY OF SUCH DAMAGE.
26b0104773SPascal Brand  */
27b0104773SPascal Brand 
28b0104773SPascal Brand #include <stdio.h>
29*fe3ccf24SJerome Forissier #include <printk.h>
30b0104773SPascal Brand 
31*fe3ccf24SJerome Forissier int snprintf(char *bf, size_t size, const char *fmt, ...)
32b0104773SPascal Brand {
33b0104773SPascal Brand 	int retval;
34b0104773SPascal Brand 	va_list ap;
35b0104773SPascal Brand 
36b0104773SPascal Brand 	va_start(ap, fmt);
37*fe3ccf24SJerome Forissier 	retval = __vsnprintf(bf, size, fmt, ap, false);
38b0104773SPascal Brand 	va_end(ap);
39d8516202SJens Wiklander 
40b0104773SPascal Brand 	return retval;
41b0104773SPascal Brand }
42b0104773SPascal Brand 
43*fe3ccf24SJerome Forissier int vsnprintf(char *bf, size_t size, const char *fmt, va_list ap)
44b0104773SPascal Brand {
45*fe3ccf24SJerome Forissier 	return __vsnprintf(bf, size, fmt, ap, false);
46b0104773SPascal Brand }
47