1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #if HAVE_VSNPRINTF
|
---|
16 |
|
---|
17 | #if !defined(ARCH_VSNPRINTF)
|
---|
18 | # define ARCH_VSNPRINTF vsnprintf
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | int
|
---|
22 | ARCH_STRING::vsnprintf(char* str, int size, const char* fmt, va_list ap)
|
---|
23 | {
|
---|
24 | int n = ::ARCH_VSNPRINTF(str, size, fmt, ap);
|
---|
25 | if (n > size) {
|
---|
26 | n = -1;
|
---|
27 | }
|
---|
28 | return n;
|
---|
29 | }
|
---|
30 |
|
---|
31 | #elif SYSAPI_UNIX // !HAVE_VSNPRINTF
|
---|
32 |
|
---|
33 | #include <stdio.h>
|
---|
34 |
|
---|
35 | int
|
---|
36 | ARCH_STRING::vsnprintf(char* str, int size, const char* fmt, va_list ap)
|
---|
37 | {
|
---|
38 | static FILE* bitbucket = fopen("/dev/null", "w");
|
---|
39 | if (bitbucket == NULL) {
|
---|
40 | // uh oh
|
---|
41 | if (size > 0) {
|
---|
42 | str[0] = '\0';
|
---|
43 | }
|
---|
44 | return 0;
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | // count the characters using the bitbucket
|
---|
48 | int n = vfprintf(bitbucket, fmt, ap);
|
---|
49 | if (n + 1 <= size) {
|
---|
50 | // it'll fit so print it into str
|
---|
51 | vsprintf(str, fmt, ap);
|
---|
52 | }
|
---|
53 | return n;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | #else // !HAVE_VSNPRINTF && !SYSAPI_UNIX
|
---|
58 |
|
---|
59 | #error vsnprintf not implemented
|
---|
60 |
|
---|
61 | #endif // !HAVE_VSNPRINTF
|
---|