~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to lib/ext2fs/inline.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2012-06-14 13:01:21 UTC
  • mfrom: (8.4.18 sid)
  • Revision ID: package-import@ubuntu.com-20120614130121-t2gct0d09jepx0y6
Tags: 1.42.4-3ubuntu1
* Merge from Debian unstable (LP: #978012), remainging changes:
  - debian/control.in: 
      Build-depend on gettext:any instead of on gettext for (cross-building)
      Drop build dependency on dc, which hasn't been needed for some time.
      Update maintainer field.
  - debian/rules:
      Block pkg-create-dbgsym from operating on this package.
      Build without dietlibc-dev, which is in universe 
  - debian/control:
      Regenerate with ./debian/rules debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * %End-Header%
12
12
 */
13
13
 
 
14
#ifndef _XOPEN_SOURCE
 
15
#define _XOPEN_SOURCE 600       /* for posix_memalign() */
 
16
#endif
14
17
 
15
18
#include "config.h"
16
19
#include <stdio.h>
45
48
        errcode_t retval;
46
49
        void **p = ptr;
47
50
 
48
 
        if (align == 0)
 
51
        if (align < 8)
49
52
                align = 8;
50
53
#ifdef HAVE_POSIX_MEMALIGN
51
54
        retval = posix_memalign(p, align, size);
64
67
                        return EXT2_ET_NO_MEMORY;
65
68
        }
66
69
#else
67
 
#error memalign or posix_memalign must be defined!
 
70
#ifdef HAVE_VALLOC
 
71
        if (align > sizeof(long long))
 
72
                *p = valloc(size);
 
73
        else
 
74
#endif
 
75
                *p = malloc(size);
 
76
        if ((unsigned long) *p & (align - 1)) {
 
77
                free(*p);
 
78
                *p = 0;
 
79
        }
 
80
        if (*p == 0)
 
81
                return EXT2_ET_NO_MEMORY;
68
82
#endif
69
83
#endif
70
84
        return 0;
71
85
}
72
86
 
 
87
#ifdef DEBUG
 
88
static int isaligned(void *ptr, unsigned long align)
 
89
{
 
90
        return (((unsigned long) ptr & (align - 1)) == 0);
 
91
}
 
92
 
 
93
static errcode_t test_memalign(unsigned long align)
 
94
{
 
95
        void *ptr = 0;
 
96
        errcode_t retval;
 
97
 
 
98
        retval = ext2fs_get_memalign(32, align, &ptr);
 
99
        if (!retval && !isaligned(ptr, align))
 
100
                retval = EINVAL;
 
101
        free(ptr);
 
102
        printf("tst_memliagn(%lu): %s\n", align, 
 
103
               retval ? error_message(retval) : "OK");
 
104
        return retval;
 
105
}
 
106
 
 
107
int main(int argc, char **argv)
 
108
{
 
109
        int err = 0;
 
110
 
 
111
        if (test_memalign(4))
 
112
                err++;
 
113
        if (test_memalign(32))
 
114
                err++;
 
115
        if (test_memalign(1024))
 
116
                err++;
 
117
        if (test_memalign(4096))
 
118
                err++;
 
119
        return err;
 
120
}
 
121
#endif