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.

vwscanf_s.c 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /*
  18. * <FUNCTION DESCRIPTION>
  19. * The vwscanf_s function is the wide-character equivalent of the vscanf_s function
  20. * The vwscanf_s function is the wide-character version of vscanf_s. The
  21. * function reads data from the standard input stream stdin and writes the
  22. * data into the location that's given by argument. Each argument must be a
  23. * pointer to a variable of a type that corresponds to a type specifier in
  24. * format. If copying occurs between strings that overlap, the behavior is
  25. * undefined.
  26. *
  27. * <INPUT PARAMETERS>
  28. * format Format control string.
  29. * argList pointer to list of arguments
  30. *
  31. * <OUTPUT PARAMETERS>
  32. * argList the converted value stored in user assigned address
  33. *
  34. * <RETURN VALUE>
  35. * Returns the number of fields successfully converted and assigned;
  36. * the return value does not include fields that were read but not assigned.
  37. * A return value of 0 indicates that no fields were assigned.
  38. * return -1 if an error occurs.
  39. */
  40. int vwscanf_s(const wchar_t *format, va_list argList)
  41. {
  42. int retVal; /* If initialization causes e838 */
  43. SecFileStream fStr;
  44. SECUREC_INIT_SEC_FILE_STREAM(fStr, SECUREC_FROM_STDIN_FLAG, stdin, 0, NULL, 0);
  45. if (format == NULL || fStr.pf == NULL) {
  46. SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
  47. return SECUREC_SCANF_EINVAL;
  48. }
  49. SECUREC_LOCK_STDIN(0, fStr.pf);
  50. retVal = SecInputSW(&fStr, format, argList);
  51. SECUREC_UNLOCK_STDIN(0, fStr.pf);
  52. if (retVal < 0) {
  53. SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
  54. return SECUREC_SCANF_EINVAL;
  55. }
  56. return retVal;
  57. }