~ubuntu-branches/ubuntu/gutsy/ntp/gutsy

« back to all changes in this revision

Viewing changes to libopts/compat/snprintf.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-18 22:41:56 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070518224156-563ruqxsxvqvoy8h
Tags: 1:4.2.4p0+dfsg-1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Update version in conflicts/replaces to that which was shipped in edgy,
    which was later than that in Debian (due to the ubuntuX).
  - Change default server to ntp.ubuntu.com.
  - Remove stop links from rc0 and rc6
  - Call dh_installinit with --error-handler
  - Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifndef HAVE_VPRINTF
 
3
#include "choke-me: no vprintf and no snprintf"
 
4
#endif
 
5
 
 
6
#if defined(HAVE_STDARG_H)
 
7
#  include <stdarg.h>
 
8
#  ifndef   VA_START
 
9
#    define VA_START(a, f)  va_start(a, f)
 
10
#    define VA_END(a)       va_end(a)
 
11
#  endif /* VA_START */
 
12
#  define SNV_USING_STDARG_H
 
13
 
 
14
#elif defined(HAVE_VARARGS_H)
 
15
#  include <varargs.h>
 
16
#  ifndef   VA_START
 
17
#    define VA_START(a, f) va_start(a)
 
18
#    define VA_END(a)    va_end(a)
 
19
#  endif /* VA_START */
 
20
#  undef  SNV_USING_STDARG_H
 
21
 
 
22
#else
 
23
#  include "must-have-stdarg-or-varargs"
 
24
#endif
 
25
 
 
26
static int
 
27
snprintf(char *str, size_t n, char const *fmt, ...)
 
28
{
 
29
    va_list ap;
 
30
    int rval;
 
31
 
 
32
#ifdef VSPRINTF_CHARSTAR
 
33
    char *rp;
 
34
    VA_START(ap, fmt);
 
35
    rp = vsprintf(str, fmt, ap);
 
36
    VA_END(ap);
 
37
    rval = strlen(rp);
 
38
 
 
39
#else
 
40
    VA_START(ap, fmt);
 
41
    rval = vsprintf(str, fmt, ap);
 
42
    VA_END(ap);
 
43
#endif
 
44
 
 
45
    if (rval > n) {
 
46
        fprintf(stderr, "snprintf buffer overrun %d > %d\n", rval, n);
 
47
        abort();
 
48
    }
 
49
    return rval;
 
50
}
 
51
 
 
52
static int
 
53
vsnprintf( char *str, size_t n, char const *fmt, va_list ap )
 
54
{
 
55
#ifdef VSPRINTF_CHARSTAR
 
56
    return (strlen(vsprintf(str, fmt, ap)));
 
57
#else
 
58
    return (vsprintf(str, fmt, ap));
 
59
#endif
 
60
}