~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to include/xalloc.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org>
 
3
 *
 
4
 * This file may be redistributed under the terms of the
 
5
 * GNU Lesser General Public License.
 
6
 *
 
7
 * General memory allocation wrappers for malloc, realloc and calloc
 
8
 */
 
9
 
 
10
#ifndef UTIL_LINUX_XALLOC_H
 
11
#define UTIL_LINUX_XALLOC_H
 
12
 
 
13
#include <stdlib.h>
 
14
#include <err.h>
 
15
#include <string.h>
 
16
 
 
17
#include "c.h"
 
18
 
 
19
#ifndef XALLOC_EXIT_CODE
 
20
# define XALLOC_EXIT_CODE EXIT_FAILURE
 
21
#endif
 
22
 
 
23
static inline __ul_alloc_size(1)
 
24
void *xmalloc(const size_t size)
 
25
{
 
26
        void *ret = malloc(size);
 
27
 
 
28
        if (!ret && size)
 
29
                err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
 
30
        return ret;
 
31
}
 
32
 
 
33
static inline __ul_alloc_size(2)
 
34
void *xrealloc(void *ptr, const size_t size)
 
35
{
 
36
        void *ret = realloc(ptr, size);
 
37
 
 
38
        if (!ret && size)
 
39
                err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
 
40
        return ret;
 
41
}
 
42
 
 
43
static inline __ul_calloc_size(1, 2)
 
44
void *xcalloc(const size_t nelems, const size_t size)
 
45
{
 
46
        void *ret = calloc(nelems, size);
 
47
 
 
48
        if (!ret && size && nelems)
 
49
                err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size);
 
50
        return ret;
 
51
}
 
52
 
 
53
static inline char *xstrdup(const char *str)
 
54
{
 
55
        char *ret = strdup(str);
 
56
 
 
57
        if (!ret && str)
 
58
                err(XALLOC_EXIT_CODE, "cannot duplicate string");
 
59
        return ret;
 
60
}
 
61
 
 
62
#endif