Add ereallocarr(3) to libutil
ereallocarr(3) wraps reallocarr(3) and embeds return status validation. Older version reviewed by <riastradh> and <christos>
This commit is contained in:
parent
a9f3026e70
commit
2cf5f6af2b
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.1971 2015/07/21 03:12:50 knakahara Exp $
|
||||
# $NetBSD: mi,v 1.1972 2015/07/26 02:20:30 kamil Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
@ -6422,6 +6422,7 @@
|
||||
./usr/share/man/cat3/erase.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/erasechar.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/erealloc.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/ereallocarr.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/erf.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/erfc.0 comp-c-catman .cat
|
||||
./usr/share/man/cat3/erfcf.0 comp-c-catman .cat
|
||||
@ -13358,6 +13359,7 @@
|
||||
./usr/share/man/html3/erase.html comp-c-htmlman html
|
||||
./usr/share/man/html3/erasechar.html comp-c-htmlman html
|
||||
./usr/share/man/html3/erealloc.html comp-c-htmlman html
|
||||
./usr/share/man/html3/ereallocarr.html comp-c-htmlman html
|
||||
./usr/share/man/html3/erf.html comp-c-htmlman html
|
||||
./usr/share/man/html3/erfc.html comp-c-htmlman html
|
||||
./usr/share/man/html3/erfcf.html comp-c-htmlman html
|
||||
@ -20206,6 +20208,7 @@
|
||||
./usr/share/man/man3/erase.3 comp-c-man .man
|
||||
./usr/share/man/man3/erasechar.3 comp-c-man .man
|
||||
./usr/share/man/man3/erealloc.3 comp-c-man .man
|
||||
./usr/share/man/man3/ereallocarr.3 comp-c-man .man
|
||||
./usr/share/man/man3/erf.3 comp-c-man .man
|
||||
./usr/share/man/man3/erfc.3 comp-c-man .man
|
||||
./usr/share/man/man3/erfcf.3 comp-c-man .man
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: util.h,v 1.66 2015/01/18 18:10:01 christos Exp $ */
|
||||
/* $NetBSD: util.h,v 1.67 2015/07/26 02:20:30 kamil Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1995
|
||||
@ -152,6 +152,7 @@ uintmax_t estrtou(const char *, int, uintmax_t, uintmax_t);
|
||||
void *ecalloc(size_t, size_t);
|
||||
void *emalloc(size_t);
|
||||
void *erealloc(void *, size_t);
|
||||
void ereallocarr(void *, size_t, size_t);
|
||||
struct __sFILE *efopen(const char *, const char *);
|
||||
int easprintf(char ** __restrict, const char * __restrict, ...)
|
||||
__printflike(2, 3);
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.76 2015/01/18 18:09:36 christos Exp $
|
||||
# $NetBSD: Makefile,v 1.77 2015/07/26 02:20:30 kamil Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||
|
||||
USE_SHLIBDIR= yes
|
||||
@ -82,6 +82,7 @@ MLINKS+=efun.3 estrtou.3
|
||||
MLINKS+=efun.3 emalloc.3
|
||||
MLINKS+=efun.3 ecalloc.3
|
||||
MLINKS+=efun.3 erealloc.3
|
||||
MLINKS+=efun.3 ereallocarr.3
|
||||
MLINKS+=efun.3 efopen.3
|
||||
MLINKS+=efun.3 evasprintf.3
|
||||
MLINKS+=stat_flags.3 string_to_flags.3
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: efun.3,v 1.11 2015/01/18 18:09:36 christos Exp $
|
||||
.\" $NetBSD: efun.3,v 1.12 2015/07/26 02:20:30 kamil Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
@ -37,6 +37,7 @@
|
||||
.Nm emalloc ,
|
||||
.Nm ecalloc ,
|
||||
.Nm erealloc ,
|
||||
.Nm ereallocarr ,
|
||||
.Nm estrdup ,
|
||||
.Nm estrndup ,
|
||||
.Nm estrlcat ,
|
||||
@ -61,6 +62,8 @@
|
||||
.Fn emalloc "size_t n"
|
||||
.Ft void *
|
||||
.Fn erealloc "void *p" "size_t n"
|
||||
.Ft void
|
||||
.Fn ereallocarr "void *p" "size_t n" "size_t s"
|
||||
.Ft char *
|
||||
.Fn estrdup "const char *s"
|
||||
.Ft char *
|
||||
@ -82,6 +85,7 @@ The
|
||||
.Fn ecalloc ,
|
||||
.Fn emalloc ,
|
||||
.Fn erealloc ,
|
||||
.Fn ereallocarr ,
|
||||
.Fn estrdup ,
|
||||
.Fn estrndup ,
|
||||
.Fn estrlcat ,
|
||||
@ -118,6 +122,7 @@ error handler will just call
|
||||
.Xr fopen 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Xr realloc 3 ,
|
||||
.Xr reallocarr 3 ,
|
||||
.Xr strdup 3 ,
|
||||
.Xr strlcat 3 ,
|
||||
.Xr strlcpy 3 ,
|
||||
@ -127,8 +132,9 @@ error handler will just call
|
||||
.Xr vasprintf 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn estrtoi
|
||||
and
|
||||
.Fn estrtoi ,
|
||||
.Fn estrtou
|
||||
and
|
||||
.Fn ereallocarr
|
||||
functions were added in
|
||||
.Nx 8 .
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $ */
|
||||
/* $NetBSD: efun.c,v 1.10 2015/07/26 02:20:30 kamil Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $");
|
||||
__RCSID("$NetBSD: efun.c,v 1.10 2015/07/26 02:20:30 kamil Exp $");
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
@ -128,6 +128,16 @@ erealloc(void *p, size_t n)
|
||||
return q;
|
||||
}
|
||||
|
||||
void
|
||||
ereallocarr(void *p, size_t n, size_t s)
|
||||
{
|
||||
int rv = reallocarr(p, n, s);
|
||||
if (rv != 0) {
|
||||
errno = rv;
|
||||
(*efunc)(1, "Cannot re-allocate %zu * %zu bytes", n, s);
|
||||
}
|
||||
}
|
||||
|
||||
FILE *
|
||||
efopen(const char *p, const char *m)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user