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.

vfwscanf_s.c 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
  20. * The vfwscanf_s function reads data from the current position of stream into
  21. * the locations given by argument (if any). Each argument must be a pointer
  22. * to a variable of a type that corresponds to a type specifier in format.
  23. * format controls the interpretation of the input fields and has the same form
  24. * and function as the format argument for scanf.
  25. *
  26. * <INPUT PARAMETERS>
  27. * stream Pointer to FILE structure.
  28. * format Format control string, see Format Specifications.
  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. * Each of these functions returns the number of fields successfully converted
  36. * and assigned; the return value does not include fields that were read but
  37. * not assigned. A return value of 0 indicates that no fields were assigned.
  38. * return -1 if an error occurs.
  39. */
  40. int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
  41. {
  42. int retVal; /* If initialization causes e838 */
  43. SecFileStream fStr;
  44. if ((stream == NULL) || (format == NULL)) {
  45. SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
  46. return SECUREC_SCANF_EINVAL;
  47. }
  48. if (stream == stdin) {
  49. return vwscanf_s(format, argList);
  50. }
  51. SECUREC_LOCK_FILE(stream);
  52. SECUREC_INIT_SEC_FILE_STREAM(fStr, SECUREC_FILE_STREAM_FLAG, stream, SECUREC_UNINITIALIZED_FILE_POS, NULL, 0);
  53. retVal = SecInputSW(&fStr, format, argList);
  54. SECUREC_UNLOCK_FILE(stream);
  55. if (retVal < 0) {
  56. SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
  57. return SECUREC_SCANF_EINVAL;
  58. }
  59. return retVal;
  60. }