source: squid-ssl/trunk/fuentes/libltdl/lt__alloc.c @ 5496

Last change on this file since 5496 was 5496, checked in by Juanma, 21 months ago

Initial release

File size: 2.2 KB
Line 
1/* lt__alloc.c -- internal memory management interface
2
3   Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
4   Written by Gary V. Vaughan, 2004
5
6   NOTE: The canonical source of this file is maintained with the
7   GNU Libtool package.  Report bugs to bug-libtool@gnu.org.
8
9GNU Libltdl is free software; you can redistribute it and/or
10modify it under the terms of the GNU Lesser General Public
11License as published by the Free Software Foundation; either
12version 2 of the License, or (at your option) any later version.
13
14As a special exception to the GNU Lesser General Public License,
15if you distribute this file as part of a program or library that
16is built using GNU Libtool, you may include this file under the
17same distribution terms that you use for the rest of that program.
18
19GNU Libltdl is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22GNU Lesser General Public License for more details.
23
24You should have received a copy of the GNU Lesser General Public
25License along with GNU Libltdl; see the file COPYING.LIB.  If not, a
26copy can be downloaded from  http://www.gnu.org/licenses/lgpl.html,
27or obtained by writing to the Free Software Foundation, Inc.,
2851 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29*/
30
31#include "lt__private.h"
32
33#include <stdio.h>
34
35#include "lt__alloc.h"
36
37static void alloc_die_default (void);
38
39void (*lt__alloc_die) (void) = alloc_die_default;
40
41/* Unless overridden, exit on memory failure.  */
42static void
43alloc_die_default (void)
44{
45  fprintf (stderr, "Out of memory.\n");
46  exit (EXIT_FAILURE);
47}
48
49void *
50lt__malloc (size_t n)
51{
52  void *mem;
53
54  if (! (mem = malloc (n)))
55    (*lt__alloc_die) ();
56
57  return mem;
58}
59
60void *
61lt__zalloc (size_t n)
62{
63  void *mem;
64
65  if ((mem = lt__malloc (n)))
66    memset (mem, 0, n);
67
68  return mem;
69}
70
71void *
72lt__realloc (void *mem, size_t n)
73{
74  if (! (mem = realloc (mem, n)))
75    (*lt__alloc_die) ();
76
77  return mem;
78}
79
80void *
81lt__memdup (void const *mem, size_t n)
82{
83  void *newmem;
84
85  if ((newmem = lt__malloc (n)))
86    return memcpy (newmem, mem, n);
87
88  return 0;
89}
90
91char *
92lt__strdup (const char *string)
93{
94  return (char *) lt__memdup (string, strlen (string) +1);
95}
Note: See TracBrowser for help on using the repository browser.