Add ereallocarr(3) to libutil ereallocarr(3) wraps reallocarr(3) and embeds return status validation. Older version reviewed by <riastradh> and <christos>diff -r1.1971 -r1.1972 src/distrib/sets/lists/comp/mi
(kamil)
--- src/distrib/sets/lists/comp/mi 2015/07/21 03:12:50 1.1971
+++ src/distrib/sets/lists/comp/mi 2015/07/26 02:20:30 1.1972
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: mi,v 1.1971 2015/07/21 03:12:50 knakahara Exp $ | 1 | # $NetBSD: mi,v 1.1972 2015/07/26 02:20:30 kamil Exp $ | |
2 | # | 2 | # | |
3 | # Note: don't delete entries from here - mark them as "obsolete" instead. | 3 | # Note: don't delete entries from here - mark them as "obsolete" instead. | |
4 | # | 4 | # | |
5 | #./usr/libdata/lint/llib-ldtrace.ln comp-c-lintlib lint,dtrace | 5 | #./usr/libdata/lint/llib-ldtrace.ln comp-c-lintlib lint,dtrace | |
6 | ./etc/mtree/set.comp comp-sys-root | 6 | ./etc/mtree/set.comp comp-sys-root | |
7 | ./usr/bin/addr2line comp-debug-bin binutils | 7 | ./usr/bin/addr2line comp-debug-bin binutils | |
8 | ./usr/bin/ar comp-util-bin binutils | 8 | ./usr/bin/ar comp-util-bin binutils | |
9 | ./usr/bin/as comp-util-bin binutils | 9 | ./usr/bin/as comp-util-bin binutils | |
10 | ./usr/bin/asa comp-fortran-bin | 10 | ./usr/bin/asa comp-fortran-bin | |
11 | ./usr/bin/atf-compile comp-obsolete obsolete | 11 | ./usr/bin/atf-compile comp-obsolete obsolete | |
12 | ./usr/bin/c++ comp-cxx-bin gcccmds | 12 | ./usr/bin/c++ comp-cxx-bin gcccmds | |
13 | ./usr/bin/c++filt comp-cxx-bin binutils | 13 | ./usr/bin/c++filt comp-cxx-bin binutils | |
14 | ./usr/bin/c89 comp-c-bin | 14 | ./usr/bin/c89 comp-c-bin | |
@@ -6412,26 +6412,27 @@ | @@ -6412,26 +6412,27 @@ | |||
6412 | ./usr/share/man/cat3/endnetpath.0 comp-c-catman .cat | 6412 | ./usr/share/man/cat3/endnetpath.0 comp-c-catman .cat | |
6413 | ./usr/share/man/cat3/endprotoent.0 comp-c-catman .cat | 6413 | ./usr/share/man/cat3/endprotoent.0 comp-c-catman .cat | |
6414 | ./usr/share/man/cat3/endpwent.0 comp-c-catman .cat | 6414 | ./usr/share/man/cat3/endpwent.0 comp-c-catman .cat | |
6415 | ./usr/share/man/cat3/endrpcent.0 comp-c-catman .cat | 6415 | ./usr/share/man/cat3/endrpcent.0 comp-c-catman .cat | |
6416 | ./usr/share/man/cat3/endservent.0 comp-c-catman .cat | 6416 | ./usr/share/man/cat3/endservent.0 comp-c-catman .cat | |
6417 | ./usr/share/man/cat3/endttyent.0 comp-c-catman .cat | 6417 | ./usr/share/man/cat3/endttyent.0 comp-c-catman .cat | |
6418 | ./usr/share/man/cat3/endusershell.0 comp-c-catman .cat | 6418 | ./usr/share/man/cat3/endusershell.0 comp-c-catman .cat | |
6419 | ./usr/share/man/cat3/endutxent.0 comp-c-catman .cat | 6419 | ./usr/share/man/cat3/endutxent.0 comp-c-catman .cat | |
6420 | ./usr/share/man/cat3/endwin.0 comp-c-catman .cat | 6420 | ./usr/share/man/cat3/endwin.0 comp-c-catman .cat | |
6421 | ./usr/share/man/cat3/erand48.0 comp-c-catman .cat | 6421 | ./usr/share/man/cat3/erand48.0 comp-c-catman .cat | |
6422 | ./usr/share/man/cat3/erase.0 comp-c-catman .cat | 6422 | ./usr/share/man/cat3/erase.0 comp-c-catman .cat | |
6423 | ./usr/share/man/cat3/erasechar.0 comp-c-catman .cat | 6423 | ./usr/share/man/cat3/erasechar.0 comp-c-catman .cat | |
6424 | ./usr/share/man/cat3/erealloc.0 comp-c-catman .cat | 6424 | ./usr/share/man/cat3/erealloc.0 comp-c-catman .cat | |
6425 | ./usr/share/man/cat3/ereallocarr.0 comp-c-catman .cat | |||
6425 | ./usr/share/man/cat3/erf.0 comp-c-catman .cat | 6426 | ./usr/share/man/cat3/erf.0 comp-c-catman .cat | |
6426 | ./usr/share/man/cat3/erfc.0 comp-c-catman .cat | 6427 | ./usr/share/man/cat3/erfc.0 comp-c-catman .cat | |
6427 | ./usr/share/man/cat3/erfcf.0 comp-c-catman .cat | 6428 | ./usr/share/man/cat3/erfcf.0 comp-c-catman .cat | |
6428 | ./usr/share/man/cat3/erfcl.0 comp-c-catman .cat | 6429 | ./usr/share/man/cat3/erfcl.0 comp-c-catman .cat | |
6429 | ./usr/share/man/cat3/erff.0 comp-c-catman .cat | 6430 | ./usr/share/man/cat3/erff.0 comp-c-catman .cat | |
6430 | ./usr/share/man/cat3/erfl.0 comp-c-catman .cat | 6431 | ./usr/share/man/cat3/erfl.0 comp-c-catman .cat | |
6431 | ./usr/share/man/cat3/err.0 comp-c-catman .cat | 6432 | ./usr/share/man/cat3/err.0 comp-c-catman .cat | |
6432 | ./usr/share/man/cat3/errc.0 comp-c-catman .cat | 6433 | ./usr/share/man/cat3/errc.0 comp-c-catman .cat | |
6433 | ./usr/share/man/cat3/error_message.0 comp-krb5-catman kerberos,.cat | 6434 | ./usr/share/man/cat3/error_message.0 comp-krb5-catman kerberos,.cat | |
6434 | ./usr/share/man/cat3/error_table_name.0 comp-krb5-catman kerberos,.cat | 6435 | ./usr/share/man/cat3/error_table_name.0 comp-krb5-catman kerberos,.cat | |
6435 | ./usr/share/man/cat3/errx.0 comp-c-catman .cat | 6436 | ./usr/share/man/cat3/errx.0 comp-c-catman .cat | |
6436 | ./usr/share/man/cat3/esetfunc.0 comp-c-catman .cat | 6437 | ./usr/share/man/cat3/esetfunc.0 comp-c-catman .cat | |
6437 | ./usr/share/man/cat3/estrdup.0 comp-c-catman .cat | 6438 | ./usr/share/man/cat3/estrdup.0 comp-c-catman .cat | |
@@ -13348,26 +13349,27 @@ | @@ -13348,26 +13349,27 @@ | |||
13348 | ./usr/share/man/html3/endnetpath.html comp-c-htmlman html | 13349 | ./usr/share/man/html3/endnetpath.html comp-c-htmlman html | |
13349 | ./usr/share/man/html3/endprotoent.html comp-c-htmlman html | 13350 | ./usr/share/man/html3/endprotoent.html comp-c-htmlman html | |
13350 | ./usr/share/man/html3/endpwent.html comp-c-htmlman html | 13351 | ./usr/share/man/html3/endpwent.html comp-c-htmlman html | |
13351 | ./usr/share/man/html3/endrpcent.html comp-c-htmlman html | 13352 | ./usr/share/man/html3/endrpcent.html comp-c-htmlman html | |
13352 | ./usr/share/man/html3/endservent.html comp-c-htmlman html | 13353 | ./usr/share/man/html3/endservent.html comp-c-htmlman html | |
13353 | ./usr/share/man/html3/endttyent.html comp-c-htmlman html | 13354 | ./usr/share/man/html3/endttyent.html comp-c-htmlman html | |
13354 | ./usr/share/man/html3/endusershell.html comp-c-htmlman html | 13355 | ./usr/share/man/html3/endusershell.html comp-c-htmlman html | |
13355 | ./usr/share/man/html3/endutxent.html comp-c-htmlman html | 13356 | ./usr/share/man/html3/endutxent.html comp-c-htmlman html | |
13356 | ./usr/share/man/html3/endwin.html comp-c-htmlman html | 13357 | ./usr/share/man/html3/endwin.html comp-c-htmlman html | |
13357 | ./usr/share/man/html3/erand48.html comp-c-htmlman html | 13358 | ./usr/share/man/html3/erand48.html comp-c-htmlman html | |
13358 | ./usr/share/man/html3/erase.html comp-c-htmlman html | 13359 | ./usr/share/man/html3/erase.html comp-c-htmlman html | |
13359 | ./usr/share/man/html3/erasechar.html comp-c-htmlman html | 13360 | ./usr/share/man/html3/erasechar.html comp-c-htmlman html | |
13360 | ./usr/share/man/html3/erealloc.html comp-c-htmlman html | 13361 | ./usr/share/man/html3/erealloc.html comp-c-htmlman html | |
13362 | ./usr/share/man/html3/ereallocarr.html comp-c-htmlman html | |||
13361 | ./usr/share/man/html3/erf.html comp-c-htmlman html | 13363 | ./usr/share/man/html3/erf.html comp-c-htmlman html | |
13362 | ./usr/share/man/html3/erfc.html comp-c-htmlman html | 13364 | ./usr/share/man/html3/erfc.html comp-c-htmlman html | |
13363 | ./usr/share/man/html3/erfcf.html comp-c-htmlman html | 13365 | ./usr/share/man/html3/erfcf.html comp-c-htmlman html | |
13364 | ./usr/share/man/html3/erfcl.html comp-c-htmlman html | 13366 | ./usr/share/man/html3/erfcl.html comp-c-htmlman html | |
13365 | ./usr/share/man/html3/erff.html comp-c-htmlman html | 13367 | ./usr/share/man/html3/erff.html comp-c-htmlman html | |
13366 | ./usr/share/man/html3/erfl.html comp-c-htmlman html | 13368 | ./usr/share/man/html3/erfl.html comp-c-htmlman html | |
13367 | ./usr/share/man/html3/err.html comp-c-htmlman html | 13369 | ./usr/share/man/html3/err.html comp-c-htmlman html | |
13368 | ./usr/share/man/html3/errc.html comp-c-htmlman html | 13370 | ./usr/share/man/html3/errc.html comp-c-htmlman html | |
13369 | ./usr/share/man/html3/error_message.html comp-krb5-htmlman kerberos,html | 13371 | ./usr/share/man/html3/error_message.html comp-krb5-htmlman kerberos,html | |
13370 | ./usr/share/man/html3/error_table_name.html comp-krb5-htmlman kerberos,html | 13372 | ./usr/share/man/html3/error_table_name.html comp-krb5-htmlman kerberos,html | |
13371 | ./usr/share/man/html3/errx.html comp-c-htmlman html | 13373 | ./usr/share/man/html3/errx.html comp-c-htmlman html | |
13372 | ./usr/share/man/html3/esetfunc.html comp-c-htmlman html | 13374 | ./usr/share/man/html3/esetfunc.html comp-c-htmlman html | |
13373 | ./usr/share/man/html3/estrdup.html comp-c-htmlman html | 13375 | ./usr/share/man/html3/estrdup.html comp-c-htmlman html | |
@@ -20196,26 +20198,27 @@ | @@ -20196,26 +20198,27 @@ | |||
20196 | ./usr/share/man/man3/endnetpath.3 comp-c-man .man | 20198 | ./usr/share/man/man3/endnetpath.3 comp-c-man .man | |
20197 | ./usr/share/man/man3/endprotoent.3 comp-c-man .man | 20199 | ./usr/share/man/man3/endprotoent.3 comp-c-man .man | |
20198 | ./usr/share/man/man3/endpwent.3 comp-c-man .man | 20200 | ./usr/share/man/man3/endpwent.3 comp-c-man .man | |
20199 | ./usr/share/man/man3/endrpcent.3 comp-c-man .man | 20201 | ./usr/share/man/man3/endrpcent.3 comp-c-man .man | |
20200 | ./usr/share/man/man3/endservent.3 comp-c-man .man | 20202 | ./usr/share/man/man3/endservent.3 comp-c-man .man | |
20201 | ./usr/share/man/man3/endttyent.3 comp-c-man .man | 20203 | ./usr/share/man/man3/endttyent.3 comp-c-man .man | |
20202 | ./usr/share/man/man3/endusershell.3 comp-c-man .man | 20204 | ./usr/share/man/man3/endusershell.3 comp-c-man .man | |
20203 | ./usr/share/man/man3/endutxent.3 comp-c-man .man | 20205 | ./usr/share/man/man3/endutxent.3 comp-c-man .man | |
20204 | ./usr/share/man/man3/endwin.3 comp-c-man .man | 20206 | ./usr/share/man/man3/endwin.3 comp-c-man .man | |
20205 | ./usr/share/man/man3/erand48.3 comp-c-man .man | 20207 | ./usr/share/man/man3/erand48.3 comp-c-man .man | |
20206 | ./usr/share/man/man3/erase.3 comp-c-man .man | 20208 | ./usr/share/man/man3/erase.3 comp-c-man .man | |
20207 | ./usr/share/man/man3/erasechar.3 comp-c-man .man | 20209 | ./usr/share/man/man3/erasechar.3 comp-c-man .man | |
20208 | ./usr/share/man/man3/erealloc.3 comp-c-man .man | 20210 | ./usr/share/man/man3/erealloc.3 comp-c-man .man | |
20211 | ./usr/share/man/man3/ereallocarr.3 comp-c-man .man | |||
20209 | ./usr/share/man/man3/erf.3 comp-c-man .man | 20212 | ./usr/share/man/man3/erf.3 comp-c-man .man | |
20210 | ./usr/share/man/man3/erfc.3 comp-c-man .man | 20213 | ./usr/share/man/man3/erfc.3 comp-c-man .man | |
20211 | ./usr/share/man/man3/erfcf.3 comp-c-man .man | 20214 | ./usr/share/man/man3/erfcf.3 comp-c-man .man | |
20212 | ./usr/share/man/man3/erfcl.3 comp-c-man .man | 20215 | ./usr/share/man/man3/erfcl.3 comp-c-man .man | |
20213 | ./usr/share/man/man3/erff.3 comp-c-man .man | 20216 | ./usr/share/man/man3/erff.3 comp-c-man .man | |
20214 | ./usr/share/man/man3/erfl.3 comp-c-man .man | 20217 | ./usr/share/man/man3/erfl.3 comp-c-man .man | |
20215 | ./usr/share/man/man3/err.3 comp-c-man .man | 20218 | ./usr/share/man/man3/err.3 comp-c-man .man | |
20216 | ./usr/share/man/man3/errc.3 comp-c-man .man | 20219 | ./usr/share/man/man3/errc.3 comp-c-man .man | |
20217 | ./usr/share/man/man3/error_message.3 comp-krb5-man kerberos,.man | 20220 | ./usr/share/man/man3/error_message.3 comp-krb5-man kerberos,.man | |
20218 | ./usr/share/man/man3/error_table_name.3 comp-krb5-man kerberos,.man | 20221 | ./usr/share/man/man3/error_table_name.3 comp-krb5-man kerberos,.man | |
20219 | ./usr/share/man/man3/errx.3 comp-c-man .man | 20222 | ./usr/share/man/man3/errx.3 comp-c-man .man | |
20220 | ./usr/share/man/man3/esetfunc.3 comp-c-man .man | 20223 | ./usr/share/man/man3/esetfunc.3 comp-c-man .man | |
20221 | ./usr/share/man/man3/estrdup.3 comp-c-man .man | 20224 | ./usr/share/man/man3/estrdup.3 comp-c-man .man |
--- src/include/util.h 2015/01/18 18:10:01 1.66
+++ src/include/util.h 2015/07/26 02:20:30 1.67
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: util.h,v 1.66 2015/01/18 18:10:01 christos Exp $ */ | 1 | /* $NetBSD: util.h,v 1.67 2015/07/26 02:20:30 kamil Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1995 | 4 | * Copyright (c) 1995 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -142,21 +142,22 @@ int disklabel_scan(struct disklabel *, | @@ -142,21 +142,22 @@ int disklabel_scan(struct disklabel *, | |||
142 | 142 | |||
143 | /* Error checked functions */ | 143 | /* Error checked functions */ | |
144 | void (*esetfunc(void (*)(int, const char *, ...))) | 144 | void (*esetfunc(void (*)(int, const char *, ...))) | |
145 | (int, const char *, ...); | 145 | (int, const char *, ...); | |
146 | size_t estrlcpy(char *, const char *, size_t); | 146 | size_t estrlcpy(char *, const char *, size_t); | |
147 | size_t estrlcat(char *, const char *, size_t); | 147 | size_t estrlcat(char *, const char *, size_t); | |
148 | char *estrdup(const char *); | 148 | char *estrdup(const char *); | |
149 | char *estrndup(const char *, size_t); | 149 | char *estrndup(const char *, size_t); | |
150 | intmax_t estrtoi(const char *, int, intmax_t, intmax_t); | 150 | intmax_t estrtoi(const char *, int, intmax_t, intmax_t); | |
151 | uintmax_t estrtou(const char *, int, uintmax_t, uintmax_t); | 151 | uintmax_t estrtou(const char *, int, uintmax_t, uintmax_t); | |
152 | void *ecalloc(size_t, size_t); | 152 | void *ecalloc(size_t, size_t); | |
153 | void *emalloc(size_t); | 153 | void *emalloc(size_t); | |
154 | void *erealloc(void *, size_t); | 154 | void *erealloc(void *, size_t); | |
155 | void ereallocarr(void *, size_t, size_t); | |||
155 | struct __sFILE *efopen(const char *, const char *); | 156 | struct __sFILE *efopen(const char *, const char *); | |
156 | int easprintf(char ** __restrict, const char * __restrict, ...) | 157 | int easprintf(char ** __restrict, const char * __restrict, ...) | |
157 | __printflike(2, 3); | 158 | __printflike(2, 3); | |
158 | int evasprintf(char ** __restrict, const char * __restrict, | 159 | int evasprintf(char ** __restrict, const char * __restrict, | |
159 | __va_list) __printflike(2, 0); | 160 | __va_list) __printflike(2, 0); | |
160 | __END_DECLS | 161 | __END_DECLS | |
161 | 162 | |||
162 | #endif /* !_UTIL_H_ */ | 163 | #endif /* !_UTIL_H_ */ |
--- src/lib/libutil/Makefile 2015/01/18 18:09:36 1.76
+++ src/lib/libutil/Makefile 2015/07/26 02:20:30 1.77
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: Makefile,v 1.76 2015/01/18 18:09:36 christos Exp $ | 1 | # $NetBSD: Makefile,v 1.77 2015/07/26 02:20:30 kamil Exp $ | |
2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | 2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | |
3 | 3 | |||
4 | USE_SHLIBDIR= yes | 4 | USE_SHLIBDIR= yes | |
5 | 5 | |||
6 | .include <bsd.own.mk> | 6 | .include <bsd.own.mk> | |
7 | 7 | |||
8 | .include "${NETBSDSRCDIR}/common/lib/libutil/Makefile.inc" | 8 | .include "${NETBSDSRCDIR}/common/lib/libutil/Makefile.inc" | |
9 | 9 | |||
10 | WARNS?= 5 | 10 | WARNS?= 5 | |
11 | LIB= util | 11 | LIB= util | |
12 | CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR} | 12 | CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR} | |
13 | LINTFLAGS+=-w | 13 | LINTFLAGS+=-w | |
14 | SRCS+= efun.c \ | 14 | SRCS+= efun.c \ | |
@@ -72,22 +72,23 @@ MLINKS+=pw_lock.3 pw_setprefix.3 | @@ -72,22 +72,23 @@ MLINKS+=pw_lock.3 pw_setprefix.3 | |||
72 | MLINKS+=pidlock.3 ttylock.3 | 72 | MLINKS+=pidlock.3 ttylock.3 | |
73 | MLINKS+=pidlock.3 ttyunlock.3 | 73 | MLINKS+=pidlock.3 ttyunlock.3 | |
74 | MLINKS+=efun.3 esetfunc.3 | 74 | MLINKS+=efun.3 esetfunc.3 | |
75 | MLINKS+=efun.3 easprintf.3 | 75 | MLINKS+=efun.3 easprintf.3 | |
76 | MLINKS+=efun.3 estrlcpy.3 | 76 | MLINKS+=efun.3 estrlcpy.3 | |
77 | MLINKS+=efun.3 estrlcat.3 | 77 | MLINKS+=efun.3 estrlcat.3 | |
78 | MLINKS+=efun.3 estrdup.3 | 78 | MLINKS+=efun.3 estrdup.3 | |
79 | MLINKS+=efun.3 estrndup.3 | 79 | MLINKS+=efun.3 estrndup.3 | |
80 | MLINKS+=efun.3 estrtoi.3 | 80 | MLINKS+=efun.3 estrtoi.3 | |
81 | MLINKS+=efun.3 estrtou.3 | 81 | MLINKS+=efun.3 estrtou.3 | |
82 | MLINKS+=efun.3 emalloc.3 | 82 | MLINKS+=efun.3 emalloc.3 | |
83 | MLINKS+=efun.3 ecalloc.3 | 83 | MLINKS+=efun.3 ecalloc.3 | |
84 | MLINKS+=efun.3 erealloc.3 | 84 | MLINKS+=efun.3 erealloc.3 | |
85 | MLINKS+=efun.3 ereallocarr.3 | |||
85 | MLINKS+=efun.3 efopen.3 | 86 | MLINKS+=efun.3 efopen.3 | |
86 | MLINKS+=efun.3 evasprintf.3 | 87 | MLINKS+=efun.3 evasprintf.3 | |
87 | MLINKS+=stat_flags.3 string_to_flags.3 | 88 | MLINKS+=stat_flags.3 string_to_flags.3 | |
88 | MLINKS+=stat_flags.3 flags_to_string.3 | 89 | MLINKS+=stat_flags.3 flags_to_string.3 | |
89 | MLINKS+=snprintb.3 snprintb_m.3 | 90 | MLINKS+=snprintb.3 snprintb_m.3 | |
90 | MLINKS+=util.3 libutil.3 | 91 | MLINKS+=util.3 libutil.3 | |
91 | MLINKS+=strpct.3 strspct.3 | 92 | MLINKS+=strpct.3 strspct.3 | |
92 | 93 | |||
93 | .include <bsd.lib.mk> | 94 | .include <bsd.lib.mk> |
--- src/lib/libutil/efun.3 2015/01/18 18:09:36 1.11
+++ src/lib/libutil/efun.3 2015/07/26 02:20:30 1.12
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: efun.3,v 1.11 2015/01/18 18:09:36 christos Exp $ | 1 | .\" $NetBSD: efun.3,v 1.12 2015/07/26 02:20:30 kamil Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 2006 The NetBSD Foundation, Inc. | 3 | .\" Copyright (c) 2006 The NetBSD Foundation, Inc. | |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | 6 | .\" This code is derived from software contributed to The NetBSD Foundation | |
7 | .\" by Christos Zoulas. | 7 | .\" by Christos Zoulas. | |
8 | .\" | 8 | .\" | |
9 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without | |
10 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | 11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | 12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | 13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
@@ -27,71 +27,75 @@ | @@ -27,71 +27,75 @@ | |||
27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | .\" POSSIBILITY OF SUCH DAMAGE. | 28 | .\" POSSIBILITY OF SUCH DAMAGE. | |
29 | .\" | 29 | .\" | |
30 | .Dd May 3, 2010 | 30 | .Dd May 3, 2010 | |
31 | .Dt EFUN 3 | 31 | .Dt EFUN 3 | |
32 | .Os | 32 | .Os | |
33 | .Sh NAME | 33 | .Sh NAME | |
34 | .Nm esetfunc , | 34 | .Nm esetfunc , | |
35 | .Nm easprintf , | 35 | .Nm easprintf , | |
36 | .Nm efopen , | 36 | .Nm efopen , | |
37 | .Nm emalloc , | 37 | .Nm emalloc , | |
38 | .Nm ecalloc , | 38 | .Nm ecalloc , | |
39 | .Nm erealloc , | 39 | .Nm erealloc , | |
40 | .Nm ereallocarr , | |||
40 | .Nm estrdup , | 41 | .Nm estrdup , | |
41 | .Nm estrndup , | 42 | .Nm estrndup , | |
42 | .Nm estrlcat , | 43 | .Nm estrlcat , | |
43 | .Nm estrlcpy , | 44 | .Nm estrlcpy , | |
44 | .Nm estrtoi , | 45 | .Nm estrtoi , | |
45 | .Nm estrtou , | 46 | .Nm estrtou , | |
46 | .Nm evasprintf | 47 | .Nm evasprintf | |
47 | .Nd error-checked utility functions | 48 | .Nd error-checked utility functions | |
48 | .Sh LIBRARY | 49 | .Sh LIBRARY | |
49 | .Lb libutil | 50 | .Lb libutil | |
50 | .Sh SYNOPSIS | 51 | .Sh SYNOPSIS | |
51 | .In util.h | 52 | .In util.h | |
52 | .Ft void (*)(int, const char *, ...) | 53 | .Ft void (*)(int, const char *, ...) | |
53 | .Fn esetfunc "void (*)(int, const char *, ...)" | 54 | .Fn esetfunc "void (*)(int, const char *, ...)" | |
54 | .Ft int | 55 | .Ft int | |
55 | .Fn easprintf "char ** restrict str" "const char * restrict fmt" "..." | 56 | .Fn easprintf "char ** restrict str" "const char * restrict fmt" "..." | |
56 | .Ft FILE * | 57 | .Ft FILE * | |
57 | .Fn efopen "const char *p" "const char *m" | 58 | .Fn efopen "const char *p" "const char *m" | |
58 | .Ft void * | 59 | .Ft void * | |
59 | .Fn ecalloc "size_t n" "size_t c" | 60 | .Fn ecalloc "size_t n" "size_t c" | |
60 | .Ft void * | 61 | .Ft void * | |
61 | .Fn emalloc "size_t n" | 62 | .Fn emalloc "size_t n" | |
62 | .Ft void * | 63 | .Ft void * | |
63 | .Fn erealloc "void *p" "size_t n" | 64 | .Fn erealloc "void *p" "size_t n" | |
65 | .Ft void | |||
66 | .Fn ereallocarr "void *p" "size_t n" "size_t s" | |||
64 | .Ft char * | 67 | .Ft char * | |
65 | .Fn estrdup "const char *s" | 68 | .Fn estrdup "const char *s" | |
66 | .Ft char * | 69 | .Ft char * | |
67 | .Fn estrndup "const char *s" "size_t len" | 70 | .Fn estrndup "const char *s" "size_t len" | |
68 | .Ft size_t | 71 | .Ft size_t | |
69 | .Fn estrlcat "char *dst" "const char *src" "size_t len" | 72 | .Fn estrlcat "char *dst" "const char *src" "size_t len" | |
70 | .Ft size_t | 73 | .Ft size_t | |
71 | .Fn estrlcpy "char *dst" "const char *src" "size_t len" | 74 | .Fn estrlcpy "char *dst" "const char *src" "size_t len" | |
72 | .Ft intmax_t | 75 | .Ft intmax_t | |
73 | .Fn estrtoi "const char * nptr" "int base" "intmax_t lo" "intmax_t hi" | 76 | .Fn estrtoi "const char * nptr" "int base" "intmax_t lo" "intmax_t hi" | |
74 | .Ft uintmax_t | 77 | .Ft uintmax_t | |
75 | .Fn estrtou "const char * nptr" "int base" "uintmax_t lo" "uintmax_t hi" | 78 | .Fn estrtou "const char * nptr" "int base" "uintmax_t lo" "uintmax_t hi" | |
76 | .Ft int | 79 | .Ft int | |
77 | .Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..." | 80 | .Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..." | |
78 | .Sh DESCRIPTION | 81 | .Sh DESCRIPTION | |
79 | The | 82 | The | |
80 | .Fn easprintf , | 83 | .Fn easprintf , | |
81 | .Fn efopen , | 84 | .Fn efopen , | |
82 | .Fn ecalloc , | 85 | .Fn ecalloc , | |
83 | .Fn emalloc , | 86 | .Fn emalloc , | |
84 | .Fn erealloc , | 87 | .Fn erealloc , | |
88 | .Fn ereallocarr , | |||
85 | .Fn estrdup , | 89 | .Fn estrdup , | |
86 | .Fn estrndup , | 90 | .Fn estrndup , | |
87 | .Fn estrlcat , | 91 | .Fn estrlcat , | |
88 | .Fn estrlcpy , | 92 | .Fn estrlcpy , | |
89 | .Fn estrtoi , | 93 | .Fn estrtoi , | |
90 | .Fn estrtou , | 94 | .Fn estrtou , | |
91 | and | 95 | and | |
92 | .Fn evasprintf | 96 | .Fn evasprintf | |
93 | functions | 97 | functions | |
94 | operate exactly as the corresponding functions that do not start with an | 98 | operate exactly as the corresponding functions that do not start with an | |
95 | .Sq e | 99 | .Sq e | |
96 | except that in case of an error, they call | 100 | except that in case of an error, they call | |
97 | the installed error handler that can be configured with | 101 | the installed error handler that can be configured with | |
@@ -108,27 +112,29 @@ The function | @@ -108,27 +112,29 @@ The function | |||
108 | returns the previous error handler function. | 112 | returns the previous error handler function. | |
109 | A | 113 | A | |
110 | .Dv NULL | 114 | .Dv NULL | |
111 | error handler will just call | 115 | error handler will just call | |
112 | .Xr exit 3 . | 116 | .Xr exit 3 . | |
113 | .Sh SEE ALSO | 117 | .Sh SEE ALSO | |
114 | .Xr asprintf 3 , | 118 | .Xr asprintf 3 , | |
115 | .Xr calloc 3 , | 119 | .Xr calloc 3 , | |
116 | .Xr err 3 , | 120 | .Xr err 3 , | |
117 | .Xr exit 3 , | 121 | .Xr exit 3 , | |
118 | .Xr fopen 3 , | 122 | .Xr fopen 3 , | |
119 | .Xr malloc 3 , | 123 | .Xr malloc 3 , | |
120 | .Xr realloc 3 , | 124 | .Xr realloc 3 , | |
125 | .Xr reallocarr 3 , | |||
121 | .Xr strdup 3 , | 126 | .Xr strdup 3 , | |
122 | .Xr strlcat 3 , | 127 | .Xr strlcat 3 , | |
123 | .Xr strlcpy 3 , | 128 | .Xr strlcpy 3 , | |
124 | .Xr strndup 3 , | 129 | .Xr strndup 3 , | |
125 | .Xr strtoi 3 , | 130 | .Xr strtoi 3 , | |
126 | .Xr strtou 3 , | 131 | .Xr strtou 3 , | |
127 | .Xr vasprintf 3 | 132 | .Xr vasprintf 3 | |
128 | .Sh HISTORY | 133 | .Sh HISTORY | |
129 | The | 134 | The | |
130 | .Fn estrtoi | 135 | .Fn estrtoi , | |
131 | and | |||
132 | .Fn estrtou | 136 | .Fn estrtou | |
137 | and | |||
138 | .Fn ereallocarr | |||
133 | functions were added in | 139 | functions were added in | |
134 | .Nx 8 . | 140 | .Nx 8 . |
--- src/lib/libutil/efun.c 2015/01/18 18:09:36 1.9
+++ src/lib/libutil/efun.c 2015/07/26 02:20:30 1.10
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $ */ | 1 | /* $NetBSD: efun.c,v 1.10 2015/07/26 02:20:30 kamil Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2006 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Christos Zoulas. | 8 | * by Christos Zoulas. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #ifdef __RCSID | 37 | #ifdef __RCSID | |
38 | __RCSID("$NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $"); | 38 | __RCSID("$NetBSD: efun.c,v 1.10 2015/07/26 02:20:30 kamil Exp $"); | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <err.h> | 41 | #include <err.h> | |
42 | #include <errno.h> | 42 | #include <errno.h> | |
43 | #include <inttypes.h> | 43 | #include <inttypes.h> | |
44 | #include <string.h> | 44 | #include <string.h> | |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> | |
46 | #include <stdio.h> | 46 | #include <stdio.h> | |
47 | #include <stdarg.h> | 47 | #include <stdarg.h> | |
48 | #include <util.h> | 48 | #include <util.h> | |
49 | 49 | |||
50 | static void (*efunc)(int, const char *, ...) = err; | 50 | static void (*efunc)(int, const char *, ...) = err; | |
51 | 51 | |||
@@ -118,26 +118,36 @@ ecalloc(size_t n, size_t s) | @@ -118,26 +118,36 @@ ecalloc(size_t n, size_t s) | |||
118 | (*efunc)(1, "Cannot allocate %zu blocks of size %zu", n, s); | 118 | (*efunc)(1, "Cannot allocate %zu blocks of size %zu", n, s); | |
119 | return p; | 119 | return p; | |
120 | } | 120 | } | |
121 | 121 | |||
122 | void * | 122 | void * | |
123 | erealloc(void *p, size_t n) | 123 | erealloc(void *p, size_t n) | |
124 | { | 124 | { | |
125 | void *q = realloc(p, n); | 125 | void *q = realloc(p, n); | |
126 | if (q == NULL && n != 0) | 126 | if (q == NULL && n != 0) | |
127 | (*efunc)(1, "Cannot re-allocate %zu bytes", n); | 127 | (*efunc)(1, "Cannot re-allocate %zu bytes", n); | |
128 | return q; | 128 | return q; | |
129 | } | 129 | } | |
130 | 130 | |||
131 | void | |||
132 | ereallocarr(void *p, size_t n, size_t s) | |||
133 | { | |||
134 | int rv = reallocarr(p, n, s); | |||
135 | if (rv != 0) { | |||
136 | errno = rv; | |||
137 | (*efunc)(1, "Cannot re-allocate %zu * %zu bytes", n, s); | |||
138 | } | |||
139 | } | |||
140 | ||||
131 | FILE * | 141 | FILE * | |
132 | efopen(const char *p, const char *m) | 142 | efopen(const char *p, const char *m) | |
133 | { | 143 | { | |
134 | FILE *fp = fopen(p, m); | 144 | FILE *fp = fopen(p, m); | |
135 | if (fp == NULL) | 145 | if (fp == NULL) | |
136 | (*efunc)(1, "Cannot open `%s'", p); | 146 | (*efunc)(1, "Cannot open `%s'", p); | |
137 | return fp; | 147 | return fp; | |
138 | } | 148 | } | |
139 | 149 | |||
140 | int | 150 | int | |
141 | easprintf(char ** __restrict ret, const char * __restrict format, ...) | 151 | easprintf(char ** __restrict ret, const char * __restrict format, ...) | |
142 | { | 152 | { | |
143 | int rv; | 153 | int rv; |