File indexing completed on 2024-11-24 04:54:36

0001 /*
0002     SPDX-License-Identifier: MPL-2.0
0003 */
0004 
0005 /* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license.
0006  * This Source Code Form is subject to the terms of the Mozilla Public
0007  * License, v. 2.0. If a copy of the MPL was not distributed with this
0008  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
0009 
0010 #ifndef BASE_H_
0011 #define BASE_H_
0012 
0013 #if !defined(nullptr) && !defined(_MSC_VER)
0014 #endif
0015 
0016 #if defined(_MSC_VER) && _MSC_VER < 1900
0017 #include <stdarg.h>
0018 #define snprintf c99_snprintf
0019 #define vsnprintf c99_vsnprintf
0020 inline int c99_vsnprintf(char *outBuf, size_t size,
0021     const char *format, va_list ap) {
0022   int count = -1;
0023   if (size != 0) {
0024     count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
0025   }
0026   if (count == -1) {
0027     count = _vscprintf(format, ap);
0028   }
0029   return count;
0030 }
0031 
0032 inline int c99_snprintf(char *outBuf, size_t size,
0033     const char *format, ...) {
0034   int count;
0035   va_list ap;
0036   va_start(ap, format);
0037   count = c99_vsnprintf(outBuf, size, format, ap);
0038   va_end(ap);
0039   return count;
0040 }
0041 #endif
0042 
0043 #endif  // BASE_H_