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.

vsscanf_s.c 3.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "secinput.h"
  17. #if defined(SECUREC_VXWORKS_PLATFORM) && (!defined(SECUREC_SYSAPI4VXWORKS) && !defined(SECUREC_CTYPE_MACRO_ADAPT))
  18. #include <ctype.h>
  19. #endif
  20. /*
  21. * <NAME>
  22. * vsscanf_s
  23. *
  24. *
  25. * <FUNCTION DESCRIPTION>
  26. * The vsscanf_s function is equivalent to sscanf_s, with the variable argument list replaced by argList
  27. * The vsscanf_s function reads data from buffer into the location given by
  28. * each argument. Every argument must be a pointer to a variable with a type
  29. * that corresponds to a type specifier in format. The format argument controls
  30. * the interpretation of the input fields and has the same form and function
  31. * as the format argument for the scanf function.
  32. * If copying takes place between strings that overlap, the behavior is undefined.
  33. *
  34. * <INPUT PARAMETERS>
  35. * buffer Stored data
  36. * format Format control string, see Format Specifications.
  37. * argList pointer to list of arguments
  38. *
  39. * <OUTPUT PARAMETERS>
  40. * argList the converted value stored in user assigned address
  41. *
  42. * <RETURN VALUE>
  43. * Each of these functions returns the number of fields successfully converted
  44. * and assigned; the return value does not include fields that were read but
  45. * not assigned. A return value of 0 indicates that no fields were assigned.
  46. * return -1 if an error occurs.
  47. */
  48. int vsscanf_s(const char *buffer, const char *format, va_list argList)
  49. {
  50. size_t count; /* If initialization causes e838 */
  51. int retVal;
  52. SecFileStream fStr;
  53. /* validation section */
  54. if (buffer == NULL || format == NULL) {
  55. SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
  56. return SECUREC_SCANF_EINVAL;
  57. }
  58. count = strlen(buffer);
  59. if (count == 0 || count > SECUREC_STRING_MAX_LEN) {
  60. SecClearDestBuf(buffer, format, argList);
  61. SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
  62. return SECUREC_SCANF_EINVAL;
  63. }
  64. #ifdef SECUREC_VXWORKS_PLATFORM
  65. /*
  66. * in vxworks platform when buffer is white string, will set first %s argument tu zero.like following useage:
  67. * " \v\f\t\r\n", "%s", str, strSize
  68. * do not check all character, just first and last character then consider it is white string
  69. */
  70. if (isspace((int)buffer[0]) && isspace((int)buffer[count - 1])) {
  71. SecClearDestBuf(buffer, format, argList);
  72. }
  73. #endif
  74. SECUREC_INIT_SEC_FILE_STREAM(fStr, SECUREC_MEM_STR_FLAG, NULL, 0, buffer, (int)count);
  75. retVal = SecInputS(&fStr, format, argList);
  76. if (retVal < 0) {
  77. SECUREC_ERROR_INVALID_PARAMTER("vsscanf_s");
  78. return SECUREC_SCANF_EINVAL;
  79. }
  80. return retVal;
  81. }
  82. #if SECUREC_IN_KERNEL
  83. EXPORT_SYMBOL(vsscanf_s);
  84. #endif