Whamcloud - gitweb
libext2fs: allow ext2fs_get_memalign() to compile w/o posix_memalign()
[tools/e2fsprogs.git] / lib / ext2fs / inline.c
1 /*
2  * inline.c --- Includes the inlined functions defined in the header
3  *      files as standalone functions, in case the application program
4  *      is compiled with inlining turned off.
5  *
6  * Copyright (C) 1993, 1994 Theodore Ts'o.
7  *
8  * %Begin-Header%
9  * This file may be redistributed under the terms of the GNU Library
10  * General Public License, version 2.
11  * %End-Header%
12  */
13
14
15 #include "config.h"
16 #include <stdio.h>
17 #include <string.h>
18 #if HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #include <fcntl.h>
22 #include <time.h>
23 #if HAVE_SYS_STAT_H
24 #include <sys/stat.h>
25 #endif
26 #if HAVE_SYS_TYPES_H
27 #include <sys/types.h>
28 #endif
29
30 #include "ext2_fs.h"
31 #define INCLUDE_INLINE_FUNCS
32 #include "ext2fs.h"
33
34 /*
35  * We used to define this as an inline, but since we are now using
36  * autoconf-defined #ifdef's, we need to export this as a
37  * library-provided function exclusively.
38  */
39 errcode_t ext2fs_get_memalign(unsigned long size,
40                               unsigned long align, void *ptr)
41 {
42         errcode_t retval;
43
44         if (align == 0)
45                 align = 8;
46 #ifdef HAVE_POSIX_MEMALIGN
47         retval = posix_memalign((void **) ptr, align, size);
48         if (retval) {
49                 if (retval == ENOMEM)
50                         return EXT2_ET_NO_MEMORY;
51                 return retval;
52         }
53 #else
54 #ifdef HAVE_MEMALIGN
55         *ptr = memalign(align, size);
56         if (*ptr == NULL) {
57                 if (errno)
58                         return errno;
59                 else
60                         return EXT2_ET_NO_MEMORY;
61         }
62 #else
63 #error memalign or posix_memalign must be defined!
64 #endif
65 #endif
66         return 0;
67 }
68