VirtualBox

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

Last change on this file since 1665 was 1246, checked in by bird, 17 years ago

Solaris build fixes.

  • Property svn:eol-style set to native
File size: 1.6 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#include "solfakes.h"
30
31
32int asprintf(char **strp, const char *fmt, ...)
33{
34 int rc;
35 va_list va;
36 va_start(va, fmt);
37 rc = vasprintf(strp, fmt, va);
38 va_end(va);
39 return rc;
40}
41
42
43int vasprintf(char **strp, const char *fmt, va_list va)
44{
45 int rc;
46 char *psz;
47 size_t cb = 1024;
48
49 *strp = NULL;
50 for (;;)
51 {
52 va_list va2;
53
54 psz = malloc(cb);
55 if (!psz)
56 return -1;
57
58#ifdef va_copy
59 va_copy(va2, va);
60 rc = snprintf(psz, cb, fmt, va2);
61 va_end(va2);
62#else
63 va2 = va;
64 rc = snprintf(psz, cb, fmt, va2);
65#endif
66 if (rc < 0 || (size_t)rc < cb)
67 break;
68 cb *= 2;
69 free(psz);
70 }
71
72 *strp = psz;
73 return rc;
74}
75
Note: See TracBrowser for help on using the repository browser.

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