| 1 |
/********************************************************************* |
| 2 |
* |
| 3 |
* Authors: Vincenzo Ciaschini - [email protected] |
| 4 |
* |
| 5 |
* Copyright (c) Members of the EGEE Collaboration. 2004-2010. |
| 6 |
* See http://www.eu-egee.org/partners/ for details on the copyright holders. |
| 7 |
* |
| 8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
* you may not use this file except in compliance with the License. |
| 10 |
* You may obtain a copy of the License at |
| 11 |
* |
| 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, software |
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
* See the License for the specific language governing permissions and |
| 18 |
* limitations under the License. |
| 19 |
* |
| 20 |
* Parts of this code may be based upon or even include verbatim pieces, |
| 21 |
* originally written by other people, in which case the original header |
| 22 |
* follows. |
| 23 |
* |
| 24 |
*********************************************************************/ |
| 25 |
|
| 26 |
#include "config.h" |
| 27 |
|
| 28 |
#include <stdio.h> |
| 29 |
#include <stdarg.h> |
| 30 |
#include <stdlib.h> |
| 31 |
#include "doio.h" |
| 32 |
|
| 33 |
char *vsnprintf_wrap(const char *format, va_list v) |
| 34 |
{ |
| 35 |
va_list w; |
| 36 |
|
| 37 |
va_copy(w,v);; |
| 38 |
char *str = NULL; |
| 39 |
int plen = 0; |
| 40 |
|
| 41 |
plen = vsnprintf(str, 0, format, v); |
| 42 |
|
| 43 |
if (plen > 0) { |
| 44 |
str = (char *)malloc(plen+1); |
| 45 |
if (str) { |
| 46 |
(void)vsnprintf(str, plen+1, format, w); |
| 47 |
va_end(w); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
return str; |
| 52 |
} |
| 53 |
|
| 54 |
char *snprintf_wrap(const char *format, ...) |
| 55 |
{ |
| 56 |
va_list v; |
| 57 |
char *str = NULL; |
| 58 |
|
| 59 |
va_start(v, format); |
| 60 |
str = vsnprintf_wrap(format, v); |
| 61 |
va_end(v); |
| 62 |
|
| 63 |
return str; |
| 64 |
} |
| 65 |
|