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