VirtualBox

source: kBuild/trunk/src/kmk/kmkbuiltin/solfakes.c@ 1116

Last change on this file since 1116 was 960, checked in by bird, 18 years ago

stdlib.h was missing.

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1/* $Id: $ */
2/** @file
3 *
4 * Fake Unix stuff for Solaris.
5 *
6 * Copyright (c) 2005-2007 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdarg.h>
28#include <stdlib.h>
29#ifdef __sun__
30# undef va_copy /* why? */
31#endif
32#include "solfakes.h"
33
34
35int asprintf(char **strp, const char *fmt, ...)
36{
37 int rc;
38 va_list va;
39 va_start(va, fmt);
40 rc = vasprintf(strp, fmt, va);
41 va_end(va);
42 return rc;
43}
44
45
46int vasprintf(char **strp, const char *fmt, va_list va)
47{
48 int rc;
49 char *psz;
50 size_t cb = 1024;
51
52 *strp = NULL;
53 for (;;)
54 {
55 va_list va2;
56
57 psz = malloc(cb);
58 if (!psz)
59 return -1;
60
61#ifdef va_copy
62 va_copy(va2, va);
63 rc = snprintf(psz, cb, fmt, va2);
64 va_end(vaCopy);
65#else
66 va2 = va;
67 rc = snprintf(psz, cb, fmt, va2);
68#endif
69 if (rc < 0 || (size_t)rc < cb)
70 break;
71 cb *= 2;
72 free(psz);
73 }
74
75 *strp = psz;
76 return rc;
77}
78
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette