diff options
author | Andy Fiddaman <omnios@citrus-it.co.uk> | 2019-09-12 23:03:03 +0000 |
---|---|---|
committer | Andy Fiddaman <omnios@citrus-it.co.uk> | 2019-09-16 16:32:55 +0000 |
commit | e7b66456775e45577294dfd79cab910ecb886cf2 (patch) | |
tree | a6b1a182c6ad2ea3b05c306e3edd8d73897dc147 | |
parent | acbbf6c3e48e6820369e27e9bd3724278b5ba825 (diff) | |
download | illumos-joyent-e7b66456775e45577294dfd79cab910ecb886cf2.tar.gz |
11680 want reallocf(3C)
Reviewed by: Igor Kozhukhov <igor@dilos.org>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Matthias Scheler <matthias.scheler@wdc.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: John Levon <john.levon@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
-rw-r--r-- | usr/src/head/stdlib.h | 6 | ||||
-rw-r--r-- | usr/src/lib/libc/amd64/Makefile | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/i386/Makefile.com | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/port/gen/reallocf.c | 28 | ||||
-rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 6 | ||||
-rw-r--r-- | usr/src/lib/libc/sparc/Makefile.com | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/sparcv9/Makefile.com | 1 | ||||
-rw-r--r-- | usr/src/man/man3c/Makefile | 3 | ||||
-rw-r--r-- | usr/src/man/man3c/malloc.3c | 30 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-library.man3c.inc | 5 |
10 files changed, 78 insertions, 4 deletions
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 d71aebf34a..9c21615994 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -517,6 +517,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 4eef3b98b7..3b5a07ec01 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 38b5264042..e4cf0e299a 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 8904d1d49a..e8c8405c42 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 4256560408..07e2878672 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 9d1c679e65..70bc84c26e 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 @@ -1169,6 +1170,7 @@ MANLINKS= FD_CLR.3c \ re_exec.3c \ readdir_r.3c \ realloc.3c \ + reallocf.3c \ reallocarray.3c \ recallocarray.3c \ regerror.3c \ @@ -1995,6 +1997,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 |