estrdup.c revision 178825
11901Swollman/*
21901Swollman * Copyright (c) 1999 - 2001 Kungliga Tekniska H�gskolan
31901Swollman * (Royal Institute of Technology, Stockholm, Sweden).
41901Swollman * All rights reserved.
51901Swollman *
61901Swollman * Redistribution and use in source and binary forms, with or without
71901Swollman * modification, are permitted provided that the following conditions
88870Srgrimes * are met:
91901Swollman *
101901Swollman * 1. Redistributions of source code must retain the above copyright
111901Swollman *    notice, this list of conditions and the following disclaimer.
128870Srgrimes *
131901Swollman * 2. Redistributions in binary form must reproduce the above copyright
141901Swollman *    notice, this list of conditions and the following disclaimer in the
151901Swollman *    documentation and/or other materials provided with the distribution.
168870Srgrimes *
171901Swollman * 3. Neither the name of the Institute nor the names of its contributors
181901Swollman *    may be used to endorse or promote products derived from this software
191901Swollman *    without specific prior written permission.
208870Srgrimes *
211901Swollman * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
221901Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231901Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248870Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
251901Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261901Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271901Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281901Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291901Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301901Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311901Swollman * SUCH DAMAGE.
321901Swollman */
3350476Speter
341901Swollman#ifdef HAVE_CONFIG_H
351901Swollman#include <config.h>
367616SwpaulRCSID("$Id: estrdup.c 21005 2007-06-08 01:54:35Z lha $");
3716283Sjraynard#endif
387616Swpaul
391901Swollman#include <stdlib.h>
401901Swollman#include <err.h>
411901Swollman
421901Swollman#include "roken.h"
4321103Speter
4421103Speter/*
4521103Speter * Like strdup but never fails.
4621103Speter */
4721103Speter
4871579Sdeischenchar * ROKEN_LIB_FUNCTION
4921103Speterestrdup (const char *str)
5021085Speter{
5121103Speter    char *tmp = strdup (str);
521901Swollman
531901Swollman    if (tmp == NULL)
548870Srgrimes	errx (1, "strdup failed");
5521103Speter    return tmp;
561901Swollman}
5721103Speter