annotate kdiff3/src-QT4/gnudiff_xmalloc.cpp @ 113:7bca1f1340f6 tip

Build fixes for Xcode 10 / Qt 5.12
author Chris Cannam
date Mon, 17 Dec 2018 11:13:01 +0000
parents fcd146072e0c
children
rev   line source
joachim99@52 1 /* xmalloc.c -- malloc with out of memory checking
joachim99@52 2
joachim99@52 3 Modified for KDiff3 by Joachim Eibl 2003.
joachim99@53 4 The original file was part of GNU DIFF.
joachim99@52 5
joachim99@52 6 Copyright (C) 1990-1999, 2000, 2002 Free Software Foundation, Inc.
joachim99@52 7
joachim99@52 8 This program is free software; you can redistribute it and/or modify
joachim99@52 9 it under the terms of the GNU General Public License as published by
joachim99@52 10 the Free Software Foundation; either version 2, or (at your option)
joachim99@52 11 any later version.
joachim99@52 12
joachim99@52 13 This program is distributed in the hope that it will be useful,
joachim99@52 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
joachim99@52 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
joachim99@52 16 GNU General Public License for more details.
joachim99@52 17
joachim99@52 18 You should have received a copy of the GNU General Public License
joachim99@52 19 along with this program; if not, write to the Free Software Foundation,
joachim99@69 20 Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */
joachim99@52 21
joachim99@80 22 # include <config-kdiff3.h>
joachim99@52 23
joachim99@52 24 #include <sys/types.h>
joachim99@52 25
joachim99@52 26
joachim99@52 27 #include <stdlib.h>
joachim99@52 28 #include <string.h>
joachim99@52 29
joachim99@52 30
joachim99@52 31 #ifndef EXIT_FAILURE
joachim99@52 32 # define EXIT_FAILURE 1
joachim99@52 33 #endif
joachim99@52 34
joachim99@53 35 #include "gnudiff_diff.h"
joachim99@52 36 /* If non NULL, call this function when memory is exhausted. */
joachim99@52 37 //void (*xalloc_fail_func) PARAMS ((void)) = 0;
joachim99@52 38 void (*xalloc_fail_func)(void) = 0;
joachim99@52 39
joachim99@52 40
joachim99@53 41 void GnuDiff::xalloc_die (void)
joachim99@52 42 {
joachim99@52 43 if (xalloc_fail_func)
joachim99@52 44 (*xalloc_fail_func) ();
joachim99@52 45 //error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
joachim99@52 46 /* The `noreturn' cannot be given to error, since it may return if
joachim99@52 47 its first argument is 0. To help compilers understand the
joachim99@52 48 xalloc_die does terminate, call exit. */
joachim99@52 49 exit (EXIT_FAILURE);
joachim99@52 50 }
joachim99@52 51
joachim99@52 52 /* Allocate N bytes of memory dynamically, with error checking. */
joachim99@52 53
joachim99@52 54 void *
joachim99@53 55 GnuDiff::xmalloc (size_t n)
joachim99@52 56 {
joachim99@52 57 void *p;
joachim99@52 58
joachim99@66 59 p = malloc (n == 0 ? 1 : n); // There are systems where malloc returns 0 for n==0.
joachim99@52 60 if (p == 0)
joachim99@52 61 xalloc_die ();
joachim99@52 62 return p;
joachim99@52 63 }
joachim99@52 64
joachim99@52 65 /* Change the size of an allocated block of memory P to N bytes,
joachim99@52 66 with error checking. */
joachim99@52 67
joachim99@52 68 void *
joachim99@53 69 GnuDiff::xrealloc (void *p, size_t n)
joachim99@52 70 {
joachim99@66 71 p = realloc (p, n==0 ? 1 : n);
joachim99@52 72 if (p == 0)
joachim99@52 73 xalloc_die ();
joachim99@52 74 return p;
joachim99@52 75 }
joachim99@52 76
joachim99@52 77
joachim99@52 78 /* Yield a new block of SIZE bytes, initialized to zero. */
joachim99@52 79
joachim99@52 80 void *
joachim99@53 81 GnuDiff::zalloc (size_t size)
joachim99@52 82 {
joachim99@52 83 void *p = xmalloc (size);
joachim99@52 84 memset (p, 0, size);
joachim99@52 85 return p;
joachim99@52 86 }