1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Memory allocation functions
6 // Copyright (C) 2007 Lasse Collin
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
23 /// Called when memory allocation fails. Prints and error message and
24 /// quits the application.
25 static void lzma_attribute((noreturn))
28 errmsg(V_ERROR, "%s", strerror(errno));
41 void *p = malloc(size);
51 xrealloc(void *ptr, size_t size)
58 ptr = realloc(ptr, size);
68 xstrdup(const char *src)
75 const size_t size = strlen(src) + 1;
76 char *dest = malloc(size);
80 memcpy(dest, src, size);
87 xstrcpy(char **dest, const char *src)
89 size_t len = strlen(src) + 1;
91 *dest = realloc(*dest, len);
95 memcpy(*dest, src, len + 1);
102 allocator(void *opaque lzma_attribute((unused)),
103 size_t nmemb lzma_attribute((unused)), size_t size)
105 return xmalloc(size);