• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
18 #define SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
19 #include "securecutil.h"
20 
21 /* flag definitions */
22 /* Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit. */
23 #define SECUREC_FLAG_SIGN           0x00001U
24 #define SECUREC_FLAG_SIGN_SPACE     0x00002U
25 #define SECUREC_FLAG_LEFT           0x00004U
26 #define SECUREC_FLAG_LEADZERO       0x00008U
27 #define SECUREC_FLAG_LONG           0x00010U
28 #define SECUREC_FLAG_SHORT          0x00020U
29 #define SECUREC_FLAG_SIGNED         0x00040U
30 #define SECUREC_FLAG_ALTERNATE      0x00080U
31 #define SECUREC_FLAG_NEGATIVE       0x00100U
32 #define SECUREC_FLAG_FORCE_OCTAL    0x00200U
33 #define SECUREC_FLAG_LONG_DOUBLE    0x00400U
34 #define SECUREC_FLAG_WIDECHAR       0x00800U
35 #define SECUREC_FLAG_LONGLONG       0x01000U
36 #define SECUREC_FLAG_CHAR           0x02000U
37 #define SECUREC_FLAG_POINTER        0x04000U
38 #define SECUREC_FLAG_I64            0x08000U
39 #define SECUREC_FLAG_PTRDIFF        0x10000U
40 #define SECUREC_FLAG_SIZE           0x20000U
41 #ifdef  SECUREC_COMPATIBLE_LINUX_FORMAT
42 #define SECUREC_FLAG_INTMAX         0x40000U
43 #endif
44 
45 /* state definitions. Identify the status of the current format */
46 typedef enum {
47     STAT_NORMAL,
48     STAT_PERCENT,
49     STAT_FLAG,
50     STAT_WIDTH,
51     STAT_DOT,
52     STAT_PRECIS,
53     STAT_SIZE,
54     STAT_TYPE,
55     STAT_INVALID
56 } SecFmtState;
57 
58 /* Format output buffer pointer and available size */
59 typedef struct {
60     int count;
61     char *cur;
62 } SecPrintfStream;
63 
64 
65 #ifndef SECUREC_BUFFER_SIZE
66 #ifdef SECUREC_STACK_SIZE_LESS_THAN_1K
67 /* SECUREC_BUFFER_SIZE Can not be less than 23 ,
68  * the length of the octal representation of 64-bit integers with zero lead
69  */
70 #define SECUREC_BUFFER_SIZE    256
71 #else
72 #define SECUREC_BUFFER_SIZE    512
73 #endif
74 #endif
75 #if SECUREC_BUFFER_SIZE < 23
76 #error SECUREC_BUFFER_SIZE Can not be less than 23
77 #endif
78 
79 #define SECUREC_MAX_PRECISION  SECUREC_BUFFER_SIZE
80 /* max. # bytes in multibyte char  ,see MB_LEN_MAX */
81 #define SECUREC_MB_LEN 16
82 /* The return value of the internal function, which is returned when truncated */
83 #define SECUREC_PRINTF_TRUNCATE (-2)
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88     extern int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList);
89 #if SECUREC_IN_KERNEL == 0
90     extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList);
91 #endif
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif
97 
98 
99