~ubuntu-branches/ubuntu/gutsy/plotutils/gutsy

« back to all changes in this revision

Viewing changes to libxmi/mi_alloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the GNU libxmi package.  Copyright (C) 1998, 1999,
 
2
   2000, 2005, Free Software Foundation, Inc.
 
3
 
 
4
   The GNU libxmi package is free software.  You may redistribute it
 
5
   and/or modify it under the terms of the GNU General Public License as
 
6
   published by the Free Software foundation; either version 2, or (at your
 
7
   option) any later version.
 
8
 
 
9
   The GNU libxmi package is distributed in the hope that it will be
 
10
   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License along
 
15
   with the GNU plotutils package; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
 
17
   Boston, MA 02110-1301, USA. */
 
18
 
1
19
/* Wrappers for standard storage allocation functions.  The tests for zero
2
20
   size, etc., are necessitated by the way in which the original X11
3
21
   scan-conversion code was written. */
10
28
#include "mi_api.h"
11
29
 
12
30
/* wrapper for malloc() */
13
 
voidptr_t 
14
 
#ifdef _HAVE_PROTOS
 
31
void * 
15
32
mi_xmalloc (size_t size)
16
 
#else
17
 
mi_xmalloc (size)
18
 
     size_t size;
19
 
#endif
20
33
{
21
 
  voidptr_t p;
 
34
  void * p;
22
35
 
23
36
  if (size == 0)
24
 
    return (voidptr_t)NULL;
 
37
    return (void *)NULL;
25
38
 
26
 
  p = (voidptr_t) malloc (size);
27
 
  if (p == (voidptr_t)NULL)
 
39
  p = (void *) malloc (size);
 
40
  if (p == (void *)NULL)
28
41
    {
29
42
      fprintf (stderr, "libxmi: ");
30
43
      perror ("out of memory");
34
47
}
35
48
 
36
49
/* wrapper for calloc() */
37
 
voidptr_t 
38
 
#ifdef _HAVE_PROTOS
 
50
void * 
39
51
mi_xcalloc (size_t nmemb, size_t size)
40
 
#else
41
 
mi_xcalloc (nmemb, size)
42
 
     size_t nmemb, size;
43
 
#endif
44
52
{
45
 
  voidptr_t p;
 
53
  void * p;
46
54
 
47
55
  if (size == 0)
48
 
    return (voidptr_t)NULL;
 
56
    return (void *)NULL;
49
57
 
50
 
  p = (voidptr_t) calloc (nmemb, size);
51
 
  if (p == (voidptr_t)NULL)
 
58
  p = (void *) calloc (nmemb, size);
 
59
  if (p == (void *)NULL)
52
60
    {
53
61
      fprintf (stderr, "libxmi: ");
54
62
      perror ("out of memory");
58
66
}
59
67
 
60
68
/* wrapper for realloc() */
61
 
voidptr_t 
62
 
#ifdef _HAVE_PROTOS
63
 
mi_xrealloc (voidptr_t p, size_t size)
64
 
#else
65
 
mi_xrealloc (p, size)
66
 
     voidptr_t p;
67
 
     size_t size;
68
 
#endif
 
69
void * 
 
70
mi_xrealloc (void * p, size_t size)
69
71
{
70
72
  if (!p)
71
73
    return mi_xmalloc (size);
74
76
      if (size == 0)
75
77
        {
76
78
          free (p);
77
 
          return (voidptr_t)NULL;
 
79
          return (void *)NULL;
78
80
        }
79
81
      
80
 
      p = (voidptr_t) realloc (p, size);
81
 
      if (p == (voidptr_t)NULL)
 
82
      p = (void *) realloc (p, size);
 
83
      if (p == (void *)NULL)
82
84
        {
83
85
          fprintf (stderr, "libxmi: ");
84
86
          perror ("out of memory");