Back to index

lightning-sunbird  0.9+nobinonly
snprintf.c
Go to the documentation of this file.
00001 #ifndef HAVE_SNPRINTF
00002 
00003 #include "watcomfx.h"
00004 #include <sys/types.h>
00005 #include <stddef.h>
00006 #include <stdio.h>
00007 
00008 #ifdef HAVE_SYS_CDEFS_H
00009 #include <sys/cdefs.h>
00010 #else
00011 #include "cdefs.h"
00012 #endif
00013 
00014 #include "prtypes.h"
00015 
00016 #include <ncompat.h>
00017 
00018 /* The OS/2 VAC compiler doesn't appear to define __STDC__ and won't let us define it either */
00019 #if defined(__STDC__) || defined(XP_OS2_VACPP)
00020 #include <stdarg.h>
00021 #else
00022 #include <varargs.h>
00023 #endif
00024 
00025 int
00026 #if defined(__STDC__) || defined(XP_OS2_VACPP)
00027 snprintf(char *str, size_t n, const char *fmt, ...)
00028 #else
00029 snprintf(str, n, fmt, va_alist)
00030        char *str;
00031        size_t n;
00032        const char *fmt;
00033        va_dcl
00034 #endif
00035 {
00036        va_list ap;
00037 #ifdef VSPRINTF_CHARSTAR
00038        char *rp;
00039 #else
00040        int rval;
00041 #endif
00042 #if defined(__STDC__) || defined(XP_OS2_VACPP)
00043        va_start(ap, fmt);
00044 #else
00045        va_start(ap);
00046 #endif
00047 #ifdef VSPRINTF_CHARSTAR
00048        rp = vsprintf(str, fmt, ap);
00049        va_end(ap);
00050        return (strlen(rp));
00051 #else
00052        rval = vsprintf(str, fmt, ap);
00053        va_end(ap);
00054        return (rval);
00055 #endif
00056 }
00057 
00058 int
00059 vsnprintf(str, n, fmt, ap)
00060        char *str;
00061        size_t n;
00062        const char *fmt;
00063        va_list ap;
00064 {
00065 #ifdef VSPRINTF_CHARSTAR
00066        return (strlen(vsprintf(str, fmt, ap)));
00067 #else
00068        return (vsprintf(str, fmt, ap));
00069 #endif
00070 }
00071 
00072 #endif /* HAVE_SNPRINTF */
00073 
00074 /* Some compilers don't like an empty source file. */
00075 static int dummy = 0;