Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 1 | /** |
| 2 | * misc.c : miscellaneous : |
| 3 | * - dealing with errors in memory allocation |
| 4 | * |
| 5 | * Copyright (c) 2008 Jean-Pierre Andre |
| 6 | * |
| 7 | * This program/include file is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program/include file is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program (in the main directory of the NTFS-3G |
| 19 | * distribution in the file COPYING); if not, write to the Free Software |
| 20 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #ifdef HAVE_STDLIB_H |
| 28 | #include <stdlib.h> |
| 29 | #endif |
| 30 | #ifdef HAVE_STRING_H |
| 31 | #include <string.h> |
| 32 | #endif |
| 33 | |
| 34 | #include "types.h" |
| 35 | #include "misc.h" |
| 36 | #include "logging.h" |
| 37 | |
| 38 | /** |
| 39 | * ntfs_calloc |
| 40 | * |
| 41 | * Return a pointer to the allocated memory or NULL if the request fails. |
| 42 | */ |
| 43 | void *ntfs_calloc(size_t size) |
| 44 | { |
| 45 | void *p; |
| 46 | |
| 47 | p = calloc(1, size); |
| 48 | if (!p) |
| 49 | ntfs_log_perror("Failed to calloc %lld bytes", (long long)size); |
| 50 | return p; |
| 51 | } |
| 52 | |
| 53 | void *ntfs_malloc(size_t size) |
| 54 | { |
| 55 | void *p; |
| 56 | |
| 57 | p = malloc(size); |
| 58 | if (!p) |
| 59 | ntfs_log_perror("Failed to malloc %lld bytes", (long long)size); |
| 60 | return p; |
| 61 | } |