Annotation of embedaddon/confuse/src/compat.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (c) 2015 Peter Rosin <peda@lysator.liu.se>
                      3:  *
                      4:  * Permission to use, copy, modify, and/or distribute this software for any
                      5:  * purpose with or without fee is hereby granted, provided that the above
                      6:  * copyright notice and this permission notice appear in all copies.
                      7:  *
                      8:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                      9:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     10:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     11:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     12:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     13:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     14:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     15:  */
                     16: 
                     17: #ifndef cfg_compat_h
                     18: #define cfg_compat_h
                     19: 
                     20: #include <stdio.h>
                     21: #include <stdarg.h>
                     22: 
                     23: #if defined _MSC_VER && _MSC_VER < 1900
                     24: #define snprintf c99_snprintf
                     25: #define vsnprintf c99_vsnprintf
                     26: 
                     27: static __inline int
                     28: c99_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
                     29: {
                     30:     int count = -1;
                     31: 
                     32:     if(size)
                     33:        count = _vsnprintf_s(buf, size, _TRUNCATE, fmt, ap);
                     34:     if(count == -1)
                     35:        count = _vscprintf(fmt, ap);
                     36: 
                     37:     return count;
                     38: }
                     39: 
                     40: static __inline int
                     41: c99_snprintf(char *buf, size_t size, const char *fmt, ...)
                     42: {
                     43:     int count;
                     44:     va_list ap;
                     45: 
                     46:     va_start(ap, fmt);
                     47:     count = c99_vsnprintf(buf, size, fmt, ap);
                     48:     va_end(ap);
                     49: 
                     50:     return count;
                     51: }
                     52: #endif
                     53: 
                     54: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>