util.h revision 204433
1139749Simp#ifndef _UTIL_H 228868Sjkh#define _UTIL_H 328868Sjkh 428868Sjkh/* 528868Sjkh * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc. 628868Sjkh * 728868Sjkh * This program is free software; you can redistribute it and/or 828868Sjkh * modify it under the terms of the GNU General Public License as 928868Sjkh * published by the Free Software Foundation; either version 2 of the 1028868Sjkh * License, or (at your option) any later version. 1128868Sjkh * 1228868Sjkh * This program is distributed in the hope that it will be useful, 1328868Sjkh * but WITHOUT ANY WARRANTY; without even the implied warranty of 1428868Sjkh * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1528868Sjkh * General Public License for more details. 1628868Sjkh * 1728868Sjkh * You should have received a copy of the GNU General Public License 1828868Sjkh * along with this program; if not, write to the Free Software 1928868Sjkh * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 2028868Sjkh * USA 2128868Sjkh */ 2228868Sjkh 2328868Sjkhstatic inline void __attribute__((noreturn)) die(char * str, ...) 2428868Sjkh{ 2528868Sjkh va_list ap; 2628868Sjkh 2728868Sjkh va_start(ap, str); 2828868Sjkh fprintf(stderr, "FATAL ERROR: "); 2928868Sjkh vfprintf(stderr, str, ap); 3028868Sjkh exit(1); 3146027Sbillf} 3228868Sjkh 3328868Sjkhstatic inline void *xmalloc(size_t len) 34119418Sobrien{ 35119418Sobrien void *new = malloc(len); 36119418Sobrien 3728868Sjkh if (!new) 3828868Sjkh die("malloc() failed\n"); 3928868Sjkh 4028868Sjkh return new; 4190684Sbde} 4290684Sbde 4328868Sjkhstatic inline void *xrealloc(void *p, size_t len) 4428868Sjkh{ 45164439Smarius void *new = realloc(p, len); 4628875Sjkh 4730354Sphk if (!new) 48136111Sphk die("realloc() failed (len=%d)\n", len); 4928868Sjkh 5028868Sjkh return new; 5161541Stanimura} 5261541Stanimura 5361541Stanimuraextern char *xstrdup(const char *s); 5461011Speter 5561541Stanimura#endif /* _UTIL_H */ 5628868Sjkh