summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorRoger A. Faulkner <Roger.Faulkner@Sun.COM>2009-01-14 06:44:41 -0800
committerRoger A. Faulkner <Roger.Faulkner@Sun.COM>2009-01-14 06:44:41 -0800
commitd09832051bb4b41ce2b3202c09fceedc089678af (patch)
treefcfac0ea5794c0254489e1106ccee80eea0fea14 /usr/src
parent050ea1a201b4b554fc4350626c5dfc5d47488630 (diff)
downloadillumos-joyent-d09832051bb4b41ce2b3202c09fceedc089678af.tar.gz
PSARC 2008/778 asprintf, vasprintf
4508459 Solaris should have asprintf() and vasprintf() functions
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/awk/awk.h6
-rw-r--r--usr/src/cmd/awk/maketab.c13
-rw-r--r--usr/src/cmd/awk/run.c6
-rw-r--r--usr/src/cmd/hal/Makefile.hal5
-rw-r--r--usr/src/cmd/oawk/makeprctab.c12
-rw-r--r--usr/src/cmd/oawk/run.c13
-rw-r--r--usr/src/cmd/ssh/include/config.h6
-rw-r--r--usr/src/head/stdio.h21
-rw-r--r--usr/src/lib/gss_mechs/mech_krb5/Makefile.com5
-rw-r--r--usr/src/lib/libc/amd64/Makefile3
-rw-r--r--usr/src/lib/libc/i386/Makefile.com3
-rw-r--r--usr/src/lib/libc/port/mapfile-vers4
-rw-r--r--usr/src/lib/libc/port/print/asprintf.c94
-rw-r--r--usr/src/lib/libc/sparc/Makefile3
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile3
15 files changed, 144 insertions, 53 deletions
diff --git a/usr/src/cmd/awk/awk.h b/usr/src/cmd/awk/awk.h
index fa5b3df0e2..9e26f2d511 100644
--- a/usr/src/cmd/awk/awk.h
+++ b/usr/src/cmd/awk/awk.h
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -30,8 +30,6 @@
#ifndef AWK_H
#define AWK_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
@@ -339,7 +337,7 @@ extern Cell *substr(Node **, int);
extern Cell *sub(Node **, int);
extern Cell *gsub(Node **, int);
extern Cell *sindex(Node **, int);
-extern Cell *asprintf(Node **, int);
+extern Cell *a_sprintf(Node **, int);
extern Cell *arith(Node **, int);
extern Cell *incrdecr(Node **, int);
extern Cell *cat(Node **, int);
diff --git a/usr/src/cmd/awk/maketab.c b/usr/src/cmd/awk/maketab.c
index 7b34e4edfe..c80e6e1c28 100644
--- a/usr/src/cmd/awk/maketab.c
+++ b/usr/src/cmd/awk/maketab.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,17 +18,15 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
-
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.5 */
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -58,7 +55,7 @@ struct xx {
{ SUB, "sub", "sub" },
{ GSUB, "gsub", "gsub" },
{ INDEX, "sindex", "sindex" },
- { SPRINTF, "asprintf", "sprintf " },
+ { SPRINTF, "a_sprintf", "sprintf " },
{ ADD, "arith", " + " },
{ MINUS, "arith", " - " },
{ MULT, "arith", " * " },
diff --git a/usr/src/cmd/awk/run.c b/usr/src/cmd/awk/run.c
index 6c6dfc1e37..62f247ac6b 100644
--- a/usr/src/cmd/awk/run.c
+++ b/usr/src/cmd/awk/run.c
@@ -20,15 +20,13 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#define tempfree(x, s) if (istemp(x)) tfree(x, s)
#define execute(p) r_execute(p)
@@ -931,7 +929,7 @@ format(uchar **bufp, uchar *s, Node *a)
/*ARGSUSED*/
Cell *
-asprintf(Node **a, int n)
+a_sprintf(Node **a, int n)
{
register Cell *x;
register Node *y;
diff --git a/usr/src/cmd/hal/Makefile.hal b/usr/src/cmd/hal/Makefile.hal
index 57d87e93eb..354f7b475e 100644
--- a/usr/src/cmd/hal/Makefile.hal
+++ b/usr/src/cmd/hal/Makefile.hal
@@ -19,11 +19,9 @@
# CDDL HEADER END
#
#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# ident "%Z%%M% %I% %E% SMI"
-#
# Definitions common for HAL code and consumers
#
@@ -49,6 +47,7 @@ HAL_CONFIG_CPPFLAGS = -DPACKAGE_DATA_DIR=\"/usr/lib\" \
-DPACKAGE_STRING=\""hal $(HAL_VERSION)"\" \
-DHALD_PID_FILE=\"/var/run/hald/pid\" \
-DHALD_SOCKET_DIR=\"/var/run/hald\" \
+ -DHAVE_ASPRINTF \
-DHAVE_POLKIT \
-DHWDATA_DIR=\"/usr/share/hwdata\" \
-DHAL_USER=\"$(HAL_USER)\" \
diff --git a/usr/src/cmd/oawk/makeprctab.c b/usr/src/cmd/oawk/makeprctab.c
index 80a9a637aa..622ac04e44 100644
--- a/usr/src/cmd/oawk/makeprctab.c
+++ b/usr/src/cmd/oawk/makeprctab.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,16 +18,15 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 1991 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include "awk.h"
/* tmaino #define NULL 0 */
#define XNULL "(null)"
@@ -53,7 +51,7 @@ struct xx
{ INDIRECT, "indirect", "$("},
{ SUBSTR, "substr", "substr"},
{ INDEX, "sindex", "sindex"},
- { SPRINTF, "asprintf", "sprintf "},
+ { SPRINTF, "a_sprintf", "sprintf "},
{ ADD, "arith", " + "},
{ MINUS, "arith", " - "},
{ MULT, "arith", " * "},
diff --git a/usr/src/cmd/oawk/run.c b/usr/src/cmd/oawk/run.c
index c119688214..3f230500dc 100644
--- a/usr/src/cmd/oawk/run.c
+++ b/usr/src/cmd/oawk/run.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -21,15 +20,13 @@
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#define DEBUG
#define tempfree(a) {if (istemp(a)) {xfree(a->sval); a->tval = 0; }}
@@ -576,7 +573,7 @@ format(wchar_t *s, NODE *a)
CELL *
-asprintf(NODE **a, int n)
+a_sprintf(NODE **a, int n)
{
CELL *x;
NODE *y;
@@ -813,7 +810,7 @@ aprintf(NODE **a, int n)
- x = asprintf(a, n);
+ x = a_sprintf(a, n);
if (a[1] == NULL) {
printf("%ws", x->sval);
tempfree(x);
diff --git a/usr/src/cmd/ssh/include/config.h b/usr/src/cmd/ssh/include/config.h
index c5f9f49eab..dcc9c47f5a 100644
--- a/usr/src/cmd/ssh/include/config.h
+++ b/usr/src/cmd/ssh/include/config.h
@@ -2,7 +2,7 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* $Id: acconfig.h,v 1.145 2002/09/26 00:38:48 tim Exp $ */
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -432,7 +432,7 @@ extern "C" {
/* #undef HAVE_ARC4RANDOM */
/* Define to 1 if you have the `asprintf' function. */
-/* #undef HAVE_ASPRINTF */
+#define HAVE_ASPRINTF 1
/* Define to 1 if you have the `b64_ntop' function. */
/* #undef HAVE_B64_NTOP */
@@ -901,7 +901,7 @@ extern "C" {
#define HAVE_UTMP_H 1
/* Define to 1 if you have the `vasprintf' function. */
-/* #undef HAVE_VASPRINTF */
+#define HAVE_VASPRINTF 1
/* Define to 1 if you have the `vhangup' function. */
#define HAVE_VHANGUP 1
diff --git a/usr/src/head/stdio.h b/usr/src/head/stdio.h
index 0c1ac2d77a..25c9fc3a43 100644
--- a/usr/src/head/stdio.h
+++ b/usr/src/head/stdio.h
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,15 +18,15 @@
*
* CDDL HEADER END
*/
-/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
-
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/* Copyright (c) 1988 AT&T */
+/* All Rights Reserved */
+
/*
* User-visible pieces of the ANSI C standard I/O package.
*/
@@ -35,8 +34,6 @@
#ifndef _STDIO_H
#define _STDIO_H
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.34.1.2 */
-
#include <sys/feature_tests.h>
#ifdef __cplusplus
@@ -276,6 +273,10 @@ extern char *tmpnam_r(char *);
(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
extern void setbuffer(FILE *, char *, size_t);
extern int setlinebuf(FILE *);
+/* PRINTFLIKE2 */
+extern int asprintf(char **, const char *, ...);
+/* PRINTFLIKE2 */
+extern int vasprintf(char **, const char *, __va_list);
#endif
/*
@@ -368,6 +369,8 @@ extern char *tmpnam_r();
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
extern void setbuffer();
extern int setlinebuf();
+extern int asprintf();
+extern int vasprintf();
#endif
#if defined(__EXTENSIONS__) || defined(__XOPEN_OR_POSIX)
diff --git a/usr/src/lib/gss_mechs/mech_krb5/Makefile.com b/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
index 0405ef777a..4b3e8cfac8 100644
--- a/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
+++ b/usr/src/lib/gss_mechs/mech_krb5/Makefile.com
@@ -19,7 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
@@ -494,7 +494,8 @@ OS_FLAGS = -DHAVE_LIBSOCKET -DHAVE_LIBNSL -DTIME_WITH_SYS_TIME \
-DHAVE_ERRNO -DHAVE_STRFTIME -DHAVE_STRPTIME -DHAVE_STRERROR \
-DHAVE_STAT -DSIZEOF_INT=4 -DPROVIDE_KERNEL_IMPORT \
-DHAVE_STDINT_H -DPOSIX_SIGNALS -DHAVE_GETENV -DHAVE_SETENV \
- -DHAVE_UNSETENV -DHAVE_FCHMOD -DHAVE_STRUCT_LIFCONF
+ -DHAVE_UNSETENV -DHAVE_FCHMOD -DHAVE_STRUCT_LIFCONF \
+ -DHAVE_VASPRINTF
CPPFLAGS += -I$(REL_PATH)krb5/ccache/file $(OS_FLAGS)
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 559d932357..0d261ea062 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -20,7 +20,7 @@
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -589,6 +589,7 @@ PORTPRINT_W= \
doprnt_w.o
PORTPRINT= \
+ asprintf.o \
doprnt.o \
fprintf.o \
printf.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index bab903b886..27028899d5 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -20,7 +20,7 @@
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -619,6 +619,7 @@ PORTPRINT_W= \
doprnt_w.o
PORTPRINT= \
+ asprintf.o \
doprnt.o \
fprintf.o \
printf.o \
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 31c82d6308..484070680d 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -19,7 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -63,6 +63,7 @@ SUNW_1.23 { # SunOS 5.11 (Solaris 11)
aio_waitn;
aio_write;
aiowrite;
+ asprintf;
assfail;
backtrace;
backtrace_symbols;
@@ -166,6 +167,7 @@ SUNW_1.23 { # SunOS 5.11 (Solaris 11)
uconv_u32tou8;
uconv_u8tou16;
uconv_u8tou32;
+ vasprintf;
vforkx;
verr;
verrx;
diff --git a/usr/src/lib/libc/port/print/asprintf.c b/usr/src/lib/libc/port/print/asprintf.c
new file mode 100644
index 0000000000..a66d1dee2f
--- /dev/null
+++ b/usr/src/lib/libc/port/print/asprintf.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 2004 Darren Tucker.
+ *
+ * Based originally on asprintf.c from OpenBSD:
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <lint.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+
+#define INIT_SZ 128
+
+/* VARARGS2 */
+int
+vasprintf(char **str, const char *format, va_list ap)
+{
+ char string[INIT_SZ];
+ char *newstr;
+ int ret;
+ size_t len;
+
+ *str = NULL;
+ ret = vsnprintf(string, INIT_SZ, format, ap);
+ if (ret < 0) /* retain the value of errno from vsnprintf() */
+ return (-1);
+ if (ret < INIT_SZ) {
+ len = ret + 1;
+ if ((newstr = malloc(len)) == NULL)
+ return (-1); /* retain errno from malloc() */
+ (void) strlcpy(newstr, string, len);
+ *str = newstr;
+ return (ret);
+ }
+ /*
+ * We will perform this loop more than once only if some other
+ * thread modifies one of the vasprintf() arguments after our
+ * previous call to vsnprintf().
+ */
+ for (;;) {
+ if (ret == INT_MAX) { /* Bad length */
+ errno = ENOMEM;
+ return (-1);
+ }
+ len = ret + 1;
+ if ((newstr = malloc(len)) == NULL)
+ return (-1); /* retain errno from malloc() */
+ ret = vsnprintf(newstr, len, format, ap);
+ if (ret < 0) { /* retain errno from vsnprintf() */
+ free(newstr);
+ return (-1);
+ }
+ if (ret < len) {
+ *str = newstr;
+ return (ret);
+ }
+ free(newstr);
+ }
+}
+
+int
+asprintf(char **str, const char *format, ...)
+{
+ va_list ap;
+ int ret;
+
+ *str = NULL;
+ va_start(ap, format);
+ ret = vasprintf(str, format, ap);
+ va_end(ap);
+
+ return (ret);
+}
diff --git a/usr/src/lib/libc/sparc/Makefile b/usr/src/lib/libc/sparc/Makefile
index 36f5ac4d42..cc787fcaf1 100644
--- a/usr/src/lib/libc/sparc/Makefile
+++ b/usr/src/lib/libc/sparc/Makefile
@@ -20,7 +20,7 @@
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -644,6 +644,7 @@ PORTPRINT_W= \
doprnt_w.o
PORTPRINT= \
+ asprintf.o \
doprnt.o \
fprintf.o \
printf.o \
diff --git a/usr/src/lib/libc/sparcv9/Makefile b/usr/src/lib/libc/sparcv9/Makefile
index 58e4629401..af36ea9cdd 100644
--- a/usr/src/lib/libc/sparcv9/Makefile
+++ b/usr/src/lib/libc/sparcv9/Makefile
@@ -20,7 +20,7 @@
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -604,6 +604,7 @@ PORTPRINT_W= \
doprnt_w.o
PORTPRINT= \
+ asprintf.o \
doprnt.o \
fprintf.o \
printf.o \