~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/libxl/osdeps.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009      Citrix Ltd.
 
3
 * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU Lesser General Public License as published
 
7
 * by the Free Software Foundation; version 2.1 only. with the special
 
8
 * exception on linking described in file LICENSE.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU Lesser General Public License for more details.
 
14
 */
 
15
 
 
16
#include "libxl_osdeps.h"
 
17
 
 
18
#include <unistd.h>
 
19
#include <stdarg.h>
 
20
#include <stdio.h>
 
21
#include <sys/time.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#ifdef NEED_OWN_ASPRINTF
 
25
 
 
26
int vasprintf(char **buffer, const char *fmt, va_list ap)
 
27
{
 
28
    int size = 0;
 
29
    int nchars;
 
30
 
 
31
    *buffer = 0;
 
32
 
 
33
    nchars = vsnprintf(*buffer, 0, fmt, ap);
 
34
 
 
35
    if (nchars >= size)
 
36
    {
 
37
        char *tmpbuff;
 
38
        /* Reallocate buffer now that we know how much space is needed. */
 
39
        size = nchars+1;
 
40
        tmpbuff = (char*)realloc(*buffer, size);
 
41
 
 
42
 
 
43
        if (tmpbuff == NULL) { /* we need to free it*/
 
44
            free(*buffer);
 
45
            return -1;
 
46
        }
 
47
 
 
48
        *buffer=tmpbuff;
 
49
        /* Try again. */
 
50
        nchars = vsnprintf(*buffer, size, fmt, ap);
 
51
    }
 
52
 
 
53
    if (nchars < 0) return nchars;
 
54
    return size;
 
55
}
 
56
 
 
57
int asprintf(char **buffer, char *fmt, ...)
 
58
{
 
59
    int status;
 
60
    va_list ap;
 
61
 
 
62
    va_start (ap, fmt);
 
63
    status = vasprintf (buffer, fmt, ap);
 
64
    va_end (ap);
 
65
    return status;
 
66
}
 
67
 
 
68
#endif