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.

vswprintf_s.c 2.2 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 "secureprintoutput.h"
  17. /*
  18. * <FUNCTION DESCRIPTION>
  19. * The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
  20. *
  21. * <INPUT PARAMETERS>
  22. * strDest Storage location for the output.
  23. * destMax Size of strDest
  24. * format Format specification.
  25. * argList pointer to list of arguments
  26. *
  27. * <OUTPUT PARAMETERS>
  28. * strDest is updated
  29. *
  30. * <RETURN VALUE>
  31. * return the number of wide characters stored in strDest, not counting the terminating null wide character.
  32. * return -1 if an error occurred.
  33. *
  34. * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
  35. */
  36. int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
  37. {
  38. int retVal; /* If initialization causes e838 */
  39. if (format == NULL || strDest == NULL || destMax == 0 || destMax > (SECUREC_WCHAR_STRING_MAX_LEN)) {
  40. if (strDest != NULL && destMax > 0) {
  41. strDest[0] = '\0';
  42. }
  43. SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
  44. return -1;
  45. }
  46. retVal = SecVswprintfImpl(strDest, destMax, format, argList);
  47. if (retVal < 0) {
  48. strDest[0] = '\0';
  49. if (retVal == SECUREC_PRINTF_TRUNCATE) {
  50. /* Buffer too small */
  51. SECUREC_ERROR_INVALID_RANGE("vswprintf_s");
  52. }
  53. SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
  54. return -1;
  55. }
  56. return retVal;
  57. }