• Main Page
  • Classes
  • Files
  • File List

vsnprintf.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2002 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include "IArchString.h"
00020 
00021 #if HAVE_VSNPRINTF
00022 
00023 #if !defined(ARCH_VSNPRINTF)
00024 #   define ARCH_VSNPRINTF vsnprintf
00025 #endif
00026 
00027 int
00028 IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
00029 {
00030     int n = ::ARCH_VSNPRINTF(str, size, fmt, ap);
00031     if (n > size) {
00032         n = -1;
00033     }
00034     return n;
00035 }
00036 
00037 #elif SYSAPI_UNIX // !HAVE_VSNPRINTF
00038 
00039 #include <stdio.h>
00040 
00041 int
00042 IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
00043 {
00044     static FILE* bitbucket = fopen("/dev/null", "w");
00045     if (bitbucket == NULL) {
00046         // uh oh
00047         if (size > 0) {
00048             str[0] = '\0';
00049         }
00050         return 0;
00051     }
00052     else {
00053         // count the characters using the bitbucket
00054         int n = vfprintf(bitbucket, fmt, ap);
00055         if (n + 1 <= size) {
00056             // it'll fit so print it into str
00057             vsprintf(str, fmt, ap);
00058         }
00059         return n;
00060     }
00061 }
00062 
00063 #else // !HAVE_VSNPRINTF && !SYSAPI_UNIX
00064 
00065 #error vsnprintf not implemented
00066 
00067 #endif // !HAVE_VSNPRINTF

Generated on Thu May 23 2013 00:00:04 for Synergy by  doxygen 1.7.1