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.
6 * Copyright (C) 1993, 1994 Theodore Ts'o.
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
15 #define _XOPEN_SOURCE 600 /* for posix_memalign() */
30 #include <sys/types.h>
37 #define INCLUDE_INLINE_FUNCS
41 * We used to define this as an inline, but since we are now using
42 * autoconf-defined #ifdef's, we need to export this as a
43 * library-provided function exclusively.
45 errcode_t ext2fs_get_memalign(unsigned long size,
46 unsigned long align, void *ptr)
53 #ifdef HAVE_POSIX_MEMALIGN
54 retval = posix_memalign(p, align, size);
56 return EXT2_ET_NO_MEMORY;
57 #else /* !HAVE_POSIX_MEMALIGN */
59 *p = memalign(align, size);
64 return EXT2_ET_NO_MEMORY;
66 #else /* !HAVE_MEMALIGN */
68 if (align > sizeof(long long))
73 if ((uintptr_t) *p & (align - 1)) {
78 return EXT2_ET_NO_MEMORY;
79 #endif /* HAVE_MEMALIGN */
80 #endif /* HAVE_POSIX_MEMALIGN */
85 static int isaligned(void *ptr, unsigned long align)
87 return (((unsigned long) ptr & (align - 1)) == 0);
90 static errcode_t test_memalign(unsigned long align)
95 retval = ext2fs_get_memalign(32, align, &ptr);
96 if (!retval && !isaligned(ptr, align))
99 printf("tst_memalign(%lu) is %s\n", align,
100 retval ? error_message(retval) : "OK");
104 int main(int argc, char **argv)
108 if (test_memalign(4))
110 if (test_memalign(32))
112 if (test_memalign(1024))
114 if (test_memalign(4096))