Annotation of parser3/src/lib/ltdl/lt__alloc.c, revision 1.2

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

E-mail: