~ubuntu-branches/ubuntu/precise/libubuntuone/precise

« back to all changes in this revision

Viewing changes to libubuntuoneui/xmalloc.c

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-02-03 12:55:22 UTC
  • mfrom: (37.1.29)
  • Revision ID: package-import@ubuntu.com-20120203125522-pa0hsa0vkstjkkf7
Tags: 2.99.3-0ubuntu1
* New upstream release.
  - Build against webkitgtk 3.0 (LP: #801182)
  - Change the API version to 3.0 to reflect the new gtk 3.0 support
  - Move the existing libubuntuone code to libubuntuoneui in preparation
    for libubuntuone containing non-gui code.
* debian/control, debian/rules, debian/*.install:
  - Update for the API version change and ui split naming
  - Bump Standards-Version
* debian/watch:
  - Update for the new version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* xmalloc.c -- malloc with out of memory checking
 
2
   Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 99 Free Software Foundation, Inc.
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; either version 2, or (at your option)
 
7
   any later version.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software Foundation,
 
16
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
17
 
 
18
#if HAVE_CONFIG_H
 
19
# include <config.h>
 
20
#endif
 
21
 
 
22
#ifndef USE_LGPL
 
23
// TODO better use #define in header file?!
 
24
#include <string.h>
 
25
#include <stdlib.h>
 
26
void *xmalloc (size_t n) {return malloc(n);}
 
27
void *xcalloc (size_t n, size_t s) {return calloc(n,s);}
 
28
void *xrealloc (void *p, size_t n) {return realloc(p,n);}
 
29
char *xstrdup (const char *p) {return strdup(p);}
 
30
 
 
31
#else // LGPL LICENSED CODE 
 
32
#if __STDC__
 
33
# define VOID void
 
34
#else
 
35
# define VOID char
 
36
#endif
 
37
 
 
38
#include <stdio.h>              /* for stderr */
 
39
 
 
40
#if STDC_HEADERS
 
41
 
 
42
#include <sys/types.h>
 
43
#include <string.h>             /* for strlen etc. */
 
44
#include <stdlib.h>
 
45
 
 
46
#else  /* !STDC_HEADERS */
 
47
 
 
48
extern size_t strlen ();
 
49
extern char *strcpy ();
 
50
 
 
51
VOID *calloc ();
 
52
VOID *malloc ();
 
53
VOID *realloc ();
 
54
void free ();
 
55
#endif
 
56
 
 
57
#if ENABLE_NLS
 
58
# include <libintl.h>
 
59
# define _(Text) gettext (Text)
 
60
#else
 
61
# define textdomain(Domain)
 
62
# define _(Text) Text
 
63
#endif
 
64
 
 
65
/* Prototypes for functions defined here.  */
 
66
#if defined (__STDC__) && __STDC__
 
67
static VOID *fixup_null_alloc (size_t n);
 
68
VOID *xmalloc (size_t n);
 
69
VOID *xcalloc (size_t n, size_t s);
 
70
VOID *xrealloc (VOID *p, size_t n);
 
71
char *xstrdup (const char *p);
 
72
#endif
 
73
 
 
74
 
 
75
static VOID *
 
76
fixup_null_alloc (n)
 
77
     size_t n;
 
78
{
 
79
  VOID *p;
 
80
 
 
81
  p = 0;
 
82
  if (n == 0)
 
83
    p = malloc ((size_t) 1);
 
84
  if (p == 0)
 
85
    {
 
86
      /* possible revisions: release some memory and re-try, print
 
87
         more information (e.g. line number of input file) */
 
88
      fprintf(stderr, _("liboauth: Memory exhausted"));
 
89
      exit(1);
 
90
    }
 
91
  return p;
 
92
}
 
93
 
 
94
/* Allocate N bytes of memory dynamically, with error checking.  */
 
95
 
 
96
VOID *
 
97
xmalloc (n)
 
98
     size_t n;
 
99
{
 
100
  VOID *p;
 
101
 
 
102
  p = malloc (n);
 
103
  if (p == 0)
 
104
    p = fixup_null_alloc (n);
 
105
  return p;
 
106
}
 
107
 
 
108
/* Allocate memory for N elements of S bytes, with error checking.  */
 
109
 
 
110
VOID *
 
111
xcalloc (n, s)
 
112
     size_t n, s;
 
113
{
 
114
  VOID *p;
 
115
 
 
116
  p = calloc (n, s);
 
117
  if (p == 0)
 
118
    p = fixup_null_alloc (n);
 
119
  return p;
 
120
}
 
121
 
 
122
/* Change the size of an allocated block of memory P to N bytes,
 
123
   with error checking.
 
124
   If P is NULL, run xmalloc.  */
 
125
 
 
126
VOID *
 
127
xrealloc (p, n)
 
128
     VOID *p;
 
129
     size_t n;
 
130
{
 
131
  if (p == 0)
 
132
    return xmalloc (n);
 
133
  p = realloc (p, n);
 
134
  if (p == 0)
 
135
    p = fixup_null_alloc (n);
 
136
  return p;
 
137
}
 
138
 
 
139
/* Make a copy of a string in a newly allocated block of memory. */
 
140
 
 
141
char *
 
142
xstrdup (str)
 
143
     const char *str;
 
144
{
 
145
  VOID *p;
 
146
 
 
147
  p = xmalloc (strlen (str) + 1);
 
148
  strcpy (p, str);
 
149
  return p;
 
150
}
 
151
#endif