summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2019-09-17 11:43:58 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2019-09-17 11:43:58 +0000
commit496f2accfa0b13708051729f478a7bdaeff40d12 (patch)
tree5588331702752d151fc0fc6e41a1e85d9f151a44
parentc0d449ee00e91a25d361ce356a1067c0dd80a5a9 (diff)
parente7b66456775e45577294dfd79cab910ecb886cf2 (diff)
downloadillumos-joyent-496f2accfa0b13708051729f478a7bdaeff40d12.tar.gz
[illumos-gate merge]
commit e7b66456775e45577294dfd79cab910ecb886cf2 11680 want reallocf(3C)
-rw-r--r--manifest1
-rw-r--r--usr/src/head/stdlib.h6
-rw-r--r--usr/src/lib/libc/amd64/Makefile1
-rw-r--r--usr/src/lib/libc/i386/Makefile.com1
-rw-r--r--usr/src/lib/libc/port/gen/reallocf.c28
-rw-r--r--usr/src/lib/libc/port/mapfile-vers6
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com1
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile.com1
-rw-r--r--usr/src/man/man3c/Makefile3
-rw-r--r--usr/src/man/man3c/malloc.3c30
-rw-r--r--usr/src/pkg/manifests/system-library.man3c.inc5
11 files changed, 79 insertions, 4 deletions
diff --git a/manifest b/manifest
index 529e5a34b5..5d7f20a5b8 100644
--- a/manifest
+++ b/manifest
@@ -13933,6 +13933,7 @@ f usr/share/man/man3c/readdir.3c 0444 root bin
s usr/share/man/man3c/readdir_r.3c=readdir.3c
s usr/share/man/man3c/realloc.3c=malloc.3c
s usr/share/man/man3c/reallocarray.3c=malloc.3c
+s usr/share/man/man3c/reallocf.3c=malloc.3c
f usr/share/man/man3c/realpath.3c 0444 root bin
f usr/share/man/man3c/reboot.3c 0444 root bin
s usr/share/man/man3c/recallocarray.3c=malloc.3c
diff --git a/usr/src/head/stdlib.h b/usr/src/head/stdlib.h
index 6ec82aa1c2..6b0d224e07 100644
--- a/usr/src/head/stdlib.h
+++ b/usr/src/head/stdlib.h
@@ -26,7 +26,10 @@
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
*/
-/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+/*
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
+ * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
+ */
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
@@ -306,6 +309,7 @@ extern void freezero(void *, size_t);
extern void *reallocarray(void *, size_t, size_t);
extern void *recallocarray(void *, size_t, size_t, size_t);
extern long long strtonum(const char *, long long, long long, const char **);
+extern void *reallocf(void *, size_t);
#endif /* !_STRICT_SYBMOLS */
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 2ba1094233..dfac8557f4 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -516,6 +516,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ reallocf.o \
recallocarray.o \
realpath.o \
reboot.o \
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 76373392b2..5b51713a06 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -553,6 +553,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ reallocf.o \
recallocarray.o \
realpath.o \
reboot.o \
diff --git a/usr/src/lib/libc/port/gen/reallocf.c b/usr/src/lib/libc/port/gen/reallocf.c
new file mode 100644
index 0000000000..43c8555811
--- /dev/null
+++ b/usr/src/lib/libc/port/gen/reallocf.c
@@ -0,0 +1,28 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
+ */
+
+#include <stdlib.h>
+
+void *
+reallocf(void *ptr, size_t size)
+{
+ void *nptr = realloc(ptr, size);
+
+ /* If size is zero, realloc will have already freed ptr. */
+ if (nptr == NULL && size != 0)
+ free(ptr);
+
+ return (nptr);
+}
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index 7bd92a9423..f2c12c1b4b 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -27,6 +27,7 @@
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2013 Gary Mills
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
#
@@ -77,6 +78,11 @@ $if _x86 && _ELF64
$add amd64
$endif
+SYMBOL_VERSION ILLUMOS_0.30 {
+ protected:
+ reallocf;
+} ILLUMOS_0.29;
+
SYMBOL_VERSION ILLUMOS_0.29 {
protected:
getrandom;
diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com
index a750be5d98..575d06efa3 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -580,6 +580,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ reallocf.o \
recallocarray.o \
realpath.o \
reboot.o \
diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com
index 810d3d9256..fe8b2b3491 100644
--- a/usr/src/lib/libc/sparcv9/Makefile.com
+++ b/usr/src/lib/libc/sparcv9/Makefile.com
@@ -537,6 +537,7 @@ PORTGEN= \
readdir.o \
readdir_r.o \
reallocarray.o \
+ reallocf.o \
recallocarray.o \
realpath.o \
reboot.o \
diff --git a/usr/src/man/man3c/Makefile b/usr/src/man/man3c/Makefile
index 540a58948e..c1eb9bbbde 100644
--- a/usr/src/man/man3c/Makefile
+++ b/usr/src/man/man3c/Makefile
@@ -16,6 +16,7 @@
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright 2018 Joyent, Inc.
# Copyright 2018 Jason King
+# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
include $(SRC)/Makefile.master
@@ -1172,6 +1173,7 @@ MANLINKS= FD_CLR.3c \
re_exec.3c \
readdir_r.3c \
realloc.3c \
+ reallocf.3c \
reallocarray.3c \
recallocarray.3c \
regerror.3c \
@@ -1998,6 +2000,7 @@ free.3c := LINKSRC = malloc.3c
freezero.3c := LINKSRC = malloc.3c
memalign.3c := LINKSRC = malloc.3c
realloc.3c := LINKSRC = malloc.3c
+reallocf.3c := LINKSRC = malloc.3c
reallocarray.3c := LINKSRC = malloc.3c
recallocarray.3c := LINKSRC = malloc.3c
valloc.3c := LINKSRC = malloc.3c
diff --git a/usr/src/man/man3c/malloc.3c b/usr/src/man/man3c/malloc.3c
index 79b7a6f4fa..1fbc0d1775 100644
--- a/usr/src/man/man3c/malloc.3c
+++ b/usr/src/man/man3c/malloc.3c
@@ -18,8 +18,9 @@
.\" Copyright 1989 AT&T
.\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2017 Nexenta Systems, Inc.
+.\" Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
.\"
-.Dd July 28, 2017
+.Dd September 12, 2019
.Dt MALLOC 3C
.Os
.Sh NAME
@@ -29,6 +30,7 @@
.Nm freezero ,
.Nm memalign ,
.Nm realloc ,
+.Nm reallocf ,
.Nm reallocarray ,
.Nm recallocarray ,
.Nm valloc ,
@@ -65,6 +67,11 @@
.Fa "size_t size"
.Fc
.Ft void *
+.Fo reallocf
+.Fa "void *ptr"
+.Fa "size_t size"
+.Fc
+.Ft void *
.Fo reallocarray
.Fa "void *ptr"
.Fa "size_t nelem"
@@ -107,6 +114,7 @@ is a pointer to a block previously allocated by
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
+.Fn reallocf ,
.Fn reallocarray ,
or
.Fn recallocarray .
@@ -197,6 +205,12 @@ is 0 and
is not a null pointer, the space pointed to is freed.
.Pp
The
+.Fn reallocf
+function behaves in the same way as
+.Fn realloc
+except that the passed pointer is freed automatically on failure.
+.Pp
+The
.Fn reallocarray
function is similar to
.Fn realloc ,
@@ -259,6 +273,7 @@ If there is no available memory,
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
+.Fn reallocf ,
.Fn reallocarray ,
.Fn recallocarray ,
.Fn memalign ,
@@ -275,6 +290,16 @@ is called with
the block pointed to by
.Fa ptr
is left intact.
+By contrast, when
+.Fn reallocf
+is called with
+.Fa size
+> 0 and returns
+.Dv NULL ,
+the block pointed to by
+.Fa ptr
+will have been freed.
+.Pp
If
.Fa size ,
.Fa nelem ,
@@ -288,6 +313,7 @@ If
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
+.Fn reallocf ,
.Fn reallocarray ,
or
.Fn recallocarray
@@ -305,6 +331,7 @@ The
.Fn malloc ,
.Fn calloc ,
.Fn realloc ,
+.Fn reallocf ,
and
.Fn reallocarray
functions will fail if:
@@ -382,6 +409,7 @@ functions are
.Pp
The
.Fn freezero ,
+.Fn reallocf ,
.Fn reallocarray ,
and
.Fn recallocarray
diff --git a/usr/src/pkg/manifests/system-library.man3c.inc b/usr/src/pkg/manifests/system-library.man3c.inc
index 846ed5bf99..3c2fa00b12 100644
--- a/usr/src/pkg/manifests/system-library.man3c.inc
+++ b/usr/src/pkg/manifests/system-library.man3c.inc
@@ -16,6 +16,7 @@
# Copyright 2014 Garrett D'Amore <garrett@damore.org>
# Copyright 2018 Jason King
# Copyright 2018, Joyent, Inc.
+# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
file path=usr/share/man/man3c/__fbufsize.3c
@@ -1242,6 +1243,7 @@ link path=usr/share/man/man3c/re_exec.3c target=re_comp.3c
link path=usr/share/man/man3c/readdir_r.3c target=readdir.3c
link path=usr/share/man/man3c/realloc.3c target=malloc.3c
link path=usr/share/man/man3c/reallocarray.3c target=malloc.3c
+link path=usr/share/man/man3c/reallocf.3c target=malloc.3c
link path=usr/share/man/man3c/recallocarray.3c target=malloc.3c
link path=usr/share/man/man3c/regerror.3c target=regcomp.3c
link path=usr/share/man/man3c/regex.3c target=regcmp.3c
@@ -1372,8 +1374,7 @@ link path=usr/share/man/man3c/thr_getspecific.3c target=thr_keycreate.3c
link path=usr/share/man/man3c/thr_keycreate_once.3c target=thr_keycreate.3c
link path=usr/share/man/man3c/thr_setconcurrency.3c \
target=thr_getconcurrency.3c
-link path=usr/share/man/man3c/thr_setname.3c \
- target=thr_getname.3c
+link path=usr/share/man/man3c/thr_setname.3c target=thr_getname.3c
link path=usr/share/man/man3c/thr_setprio.3c target=thr_getprio.3c
link path=usr/share/man/man3c/thr_setspecific.3c target=thr_keycreate.3c
link path=usr/share/man/man3c/thrd_sleep.3c target=nanosleep.3c