1.\" $NetBSD: ecalloc.3,v 1.1.1.3 2014/04/24 12:45:52 pettai Exp $ 2.\" 3.\" Copyright (c) 2001, 2003 Kungliga Tekniska Högskolan 4.\" (Royal Institute of Technology, Stockholm, Sweden). 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" 3. Neither the name of the Institute nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" Id 34.\" 35.Dd August 14, 2003 36.Dt ECALLOC 3 37.Os 38.Sh NAME 39.Nm ecalloc , 40.Nm emalloc , 41.Nm eread , 42.Nm erealloc , 43.Nm esetenv , 44.Nm estrdup , 45.Nm ewrite 46.Nd exit-on-failure wrapper functions 47.Sh LIBRARY 48The roken library (libroken, -lroken) 49.Sh SYNOPSIS 50.Fd #include <roken.h> 51.Ft "void *" 52.Fn ecalloc "size_t number" "size_t size" 53.Ft "void *" 54.Fn emalloc "size_t sz" 55.Ft ssize_t 56.Fn eread "int fd" "void *buf" "size_t nbytes" 57.Ft "void *" 58.Fn erealloc "void *ptr" "size_t sz" 59.Ft void 60.Fn esetenv "const char *var" "const char *val" "int rewrite" 61.Ft "char *" 62.Fn estrdup "const char *str" 63.Ft ssize_t 64.Fn ewrite "int fd" "const void *buf" "size_t nbytes" 65.Sh DESCRIPTION 66These functions do the same as the ones without the 67.Dq e 68prefix, but if there is an error they will print a message with 69.Xr errx 3 , 70and exit. For 71.Nm eread 72and 73.Nm ewrite 74this is also true for partial data. 75.Pp 76This is useful in applications when there is no need for a more 77advanced failure mode. 78.Sh SEE ALSO 79.Xr read 2 , 80.Xr write 2 , 81.Xr calloc 3 , 82.Xr errx 3 , 83.Xr malloc 3 , 84.Xr realloc 3 , 85.Xr setenv 3 , 86.Xr strdup 3 87