updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / var / da / makedepf90-2.8.8 / xmalloc.c
blob32663254d178c817727c99d43a9c40819dcd3aae
1 /*
2 * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License version 2 as published by the Free Software
7 * Foundation.
9 * This program is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
21 #include <stdlib.h>
22 #include <string.h>
23 #include <assert.h>
24 #include "errormesg.h"
25 #include "xmalloc.h"
27 void *xmalloc (size_t bytes)
29 void *new;
31 new = malloc (bytes);
32 if (!new) fatal_error ("memory allocation error");
34 return new;
38 void *xrealloc(void *ptr, size_t size)
40 void *new;
42 new = realloc(ptr, size);
43 if (!new) fatal_error ("memory allocation error");
45 return new;
49 char *xstrdup (const char *str)
51 char *new;
53 new = (char *) xmalloc ((strlen(str) + 1)*sizeof(char));
54 strcpy(new, str);
56 return new;
60 char *xstrndup (const char *str, size_t maxl)
62 char *new;
64 assert (maxl >= 0);
66 new = (char *) xmalloc ((maxl + 1)*sizeof(char));
67 strncpy (new, str, maxl);
68 new[maxl] = '\0';
70 return new;