• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 #ifndef __SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
17 #define __SEC_INPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
18 #include "securecutil.h"
19 
20 #define SECUREC_SCANF_EINVAL (-1)
21 #define SECUREC_SCANF_ERROR_PARA (-2)
22 
23 /* for internal stream flag */
24 #define SECUREC_MEM_STR_FLAG 0X01
25 #define SECUREC_FILE_STREAM_FLAG 0X02
26 #define SECUREC_FROM_STDIN_FLAG 0X04
27 #define SECUREC_LOAD_FILE_TO_MEM_FLAG 0X08
28 
29 #define SECUREC_UNINITIALIZED_FILE_POS (-1)
30 #define SECUREC_BOM_HEADER_SIZE (2)
31 #define SECUREC_UTF8_BOM_HEADER_SIZE (3)
32 
33 typedef struct {
34     int count;                  /* the size of buffered string in bytes */
35     const char *cur;            /* the pointer to next read position */
36     char *base;                 /* the pointer to the header of buffered string */
37     unsigned int flag;          /* mark the properties of input stream */
38     FILE *pf;                   /* the file pointer */
39     int fileRealRead;
40     long oriFilePos;            /* the original position of file offset when fscanf is called */
41 #if defined(SECUREC_NO_STD_UNGETC)
42     unsigned int lastChar;      /* the char code of last input */
43     int fUnget;                 /* the boolean flag of pushing a char back to read stream */
44 #endif
45 } SecFileStream;
46 
47 #if defined(SECUREC_NO_STD_UNGETC)
48 #define SECUREC_INIT_SEC_FILE_STREAM {0, NULL, NULL, 0, NULL, 0, 0, 0, 0}
49 #else
50 #define SECUREC_INIT_SEC_FILE_STREAM {0, NULL, NULL, 0, NULL, 0, 0}
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57     extern int SecInputS(SecFileStream *stream, const char *format, va_list arglist);
58     extern int SecInputSW(SecFileStream *stream, const wchar_t *format, va_list arglist);
59     extern void SecClearDestBuf(const char *buffer, const char *cformat, va_list arglist);
60     extern void SecClearDestBufW(const wchar_t *buffer, const wchar_t *cformat, va_list arglist);
61 
62 /* 20150105 For software and hardware decoupling,such as UMG */
63 #ifdef SECUREC_SYSAPI4VXWORKS
64 #ifdef feof
65 #undef feof
66 #endif
67     extern int feof(FILE *stream);
68 
69 #ifndef isspace
70 #define isspace(c)      (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
71 #endif
72 #ifndef isascii
73 #define isascii(c)       (((unsigned char)(c))<=0x7f)
74 #endif
75 #ifndef isupper
76 #define isupper(c)       ((c) >= 'A' && (c) <= 'Z')
77 #endif
78 #ifndef islower
79 #define islower(c)       ((c) >= 'a' && (c) <= 'z')
80 #endif
81 #ifndef isalpha
82 #define isalpha(c)       (isupper(c) || (islower(c)))
83 #endif
84 #ifndef isdigit
85 #define isdigit(c)       ((c) >= '0' && (c) <= '9')
86 #endif
87 #ifndef isxdigit
88 #define isxupper(c)      ((c) >= 'A' && (c) <= 'F')
89 #define isxlower(c)      ((c) >= 'a' && (c) <= 'f')
90 #define isxdigit(c)      (isdigit(c) || isxupper(c) ||isxlower(c))
91 #endif
92 #endif
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 /* Reserved file operation macro interface */
98 #define SECUREC_LOCK_FILE(s)
99 #define SECUREC_UNLOCK_FILE(s)
100 #define SECUREC_LOCK_STDIN(i,s)
101 #define SECUREC_UNLOCK_STDIN(i,s)
102 #endif
103 
104 
105