1 /*############################################################################
2 # Copyright 2016 Intel Corporation
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
17 /*!
18 * \file
19 * \brief Buffer handling utilities implementation.
20 */
21
22 #include <stdarg.h>
23 #include <util/strutil.h>
24
25 #include <stdio.h>
26 #if defined(_MSC_VER) && _MSC_VER < 1900
vsnprintf(char * outBuf,size_t size,const char * format,va_list ap)27 int vsnprintf(char* outBuf, size_t size, const char* format, va_list ap) {
28 int count = -1;
29
30 if (0 != size) {
31 count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
32 }
33 if (-1 == count) {
34 // vsnprintf returns "The number of characters that would have been
35 // written if n had been sufficiently large" however _vsnprintf_s
36 // returns -1 if the content was truncated.
37 // _vscprintf calculates that value
38 count = _vscprintf(format, ap);
39 }
40 return count;
41 }
42
snprintf(char * outBuf,size_t size,const char * format,...)43 int snprintf(char* outBuf, size_t size, const char* format, ...) {
44 int count;
45 va_list ap;
46
47 va_start(ap, format);
48 count = vsnprintf(outBuf, size, format, ap);
49 va_end(ap);
50
51 return count;
52 }
53 #endif
54