source: ntrip/trunk/BNC/RTCM/format.h@ 87

Last change on this file since 87 was 35, checked in by mervart, 19 years ago

Imported sources

File size: 1.0 KB
Line 
1// -*- C++ -*-
2//
3// $Id
4
5#include<cmath>
6
7#if !defined(__format_h__)
8#define __format_h__
9
10#if !defined(u_char)
11#define u_char unsigned char
12#endif
13
14#if !defined(u_int)
15#define u_int unsigned int
16#endif
17
18#if !defined(__GNUC__)
19double rint(double val);
20#endif
21
22#include <cstdio>
23#include <cstdarg>
24#include <string>
25
26using namespace std;
27
28//
29// string format(const char * form , ... );
30//
31// Purpose:
32// To generate fprintf-like formatted strings
33//
34#if defined(__GNUC__)
35static inline
36string format(const char * form , ... ) __attribute__ ((format (printf, 1, 2)));
37#endif
38
39static inline
40string format(const char * form , ... ) {
41 const int myBUFF_SIZE = 1024;
42 char most2long1s2short[myBUFF_SIZE];
43 va_list ap;
44 va_start(ap,form);
45#if defined(__GNUC__)
46 // have vsnprintf
47 if(vsnprintf(most2long1s2short,myBUFF_SIZE,form,ap) == -1)
48 most2long1s2short[myBUFF_SIZE] =0x00;
49 return string(most2long1s2short);
50#else
51 most2long1s2short[myBUFF_SIZE] =0x00;
52 vsprintf(most2long1s2short,form,ap);
53 return string(most2long1s2short);
54#endif
55}
56
57#endif
Note: See TracBrowser for help on using the repository browser.