1 /*
2 * Copyright (c) 2021 GOODIX.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdarg.h>
17 #include <stdio.h>
18 #include "securec.h"
19
20 #define BUFSIZE 256
21
22
printf(const char * __restrict __format,...)23 int printf(const char *__restrict __format, ...)
24 {
25 char buf[BUFSIZE] = { 0 };
26 int len;
27 va_list ap;
28 va_start(ap, __format);
29 len = vsnprintf_s(buf, sizeof(buf), BUFSIZE - 1, __format, ap);
30 if (len < 0) {
31 return len;
32 }
33
34 va_end(ap);
35 if (len > 0) {
36 char const *s = buf;
37 while (*s) {
38 _putchar(*s++);
39 }
40 }
41 return len;
42 }
43
sprintf(char * __restrict __s,const char * __restrict __format,...)44 int sprintf(char *__restrict __s, const char *__restrict __format, ...)
45 {
46 va_list args;
47 int val;
48
49 va_start(args, __format);
50 val = vsprintf_s(__s, BUFSIZE - 1, __format, args);
51 va_end(args);
52
53 return val;
54 }
55
56