You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

secureprintoutput.h 3.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
  17. #define SECUREPRINTOUTPUT_H_E950DA2C_902F_4B15_BECD_948E99090D9C
  18. #include "securecutil.h"
  19. /* flag definitions */
  20. /* Using macros instead of enumerations is because some of the enumerated types under the compiler are 16bit. */
  21. #define SECUREC_FLAG_SIGN 0x00001U
  22. #define SECUREC_FLAG_SIGN_SPACE 0x00002U
  23. #define SECUREC_FLAG_LEFT 0x00004U
  24. #define SECUREC_FLAG_LEADZERO 0x00008U
  25. #define SECUREC_FLAG_LONG 0x00010U
  26. #define SECUREC_FLAG_SHORT 0x00020U
  27. #define SECUREC_FLAG_SIGNED 0x00040U
  28. #define SECUREC_FLAG_ALTERNATE 0x00080U
  29. #define SECUREC_FLAG_NEGATIVE 0x00100U
  30. #define SECUREC_FLAG_FORCE_OCTAL 0x00200U
  31. #define SECUREC_FLAG_LONG_DOUBLE 0x00400U
  32. #define SECUREC_FLAG_WIDECHAR 0x00800U
  33. #define SECUREC_FLAG_LONGLONG 0x01000U
  34. #define SECUREC_FLAG_CHAR 0x02000U
  35. #define SECUREC_FLAG_POINTER 0x04000U
  36. #define SECUREC_FLAG_I64 0x08000U
  37. #define SECUREC_FLAG_PTRDIFF 0x10000U
  38. #define SECUREC_FLAG_SIZE 0x20000U
  39. #ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
  40. #define SECUREC_FLAG_INTMAX 0x40000U
  41. #endif
  42. /* state definitions. Identify the status of the current format */
  43. typedef enum {
  44. STAT_NORMAL,
  45. STAT_PERCENT,
  46. STAT_FLAG,
  47. STAT_WIDTH,
  48. STAT_DOT,
  49. STAT_PRECIS,
  50. STAT_SIZE,
  51. STAT_TYPE,
  52. STAT_INVALID
  53. } SecFmtState;
  54. /* Format output buffer pointer and available size */
  55. typedef struct {
  56. int count;
  57. char *cur;
  58. } SecPrintfStream;
  59. #ifndef SECUREC_BUFFER_SIZE
  60. #ifdef SECUREC_STACK_SIZE_LESS_THAN_1K
  61. /* SECUREC_BUFFER_SIZE Can not be less than 23 ,
  62. * the length of the octal representation of 64-bit integers with zero lead
  63. */
  64. #define SECUREC_BUFFER_SIZE 256
  65. #else
  66. #define SECUREC_BUFFER_SIZE 512
  67. #endif
  68. #endif
  69. #if SECUREC_BUFFER_SIZE < 23
  70. #error SECUREC_BUFFER_SIZE Can not be less than 23
  71. #endif
  72. #define SECUREC_MAX_PRECISION SECUREC_BUFFER_SIZE
  73. /* max. # bytes in multibyte char ,see MB_LEN_MAX */
  74. #define SECUREC_MB_LEN 16
  75. /* The return value of the internal function, which is returned when truncated */
  76. #define SECUREC_PRINTF_TRUNCATE (-2)
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif
  80. extern int SecVsnprintfImpl(char *string, size_t count, const char *format, va_list argList);
  81. #if SECUREC_IN_KERNEL == 0
  82. extern int SecVswprintfImpl(wchar_t *string, size_t sizeInWchar, const wchar_t *format, va_list argList);
  83. #endif
  84. #ifdef __cplusplus
  85. }
  86. #endif
  87. #endif