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);
57 return EXT2_ET_NO_MEMORY;
62 *p = memalign(align, size);
67 return EXT2_ET_NO_MEMORY;
71 if (align > sizeof(long long))
76 if ((unsigned long) *p & (align - 1)) {
81 return EXT2_ET_NO_MEMORY;
88 static int isaligned(void *ptr, unsigned long align)
90 return (((unsigned long) ptr & (align - 1)) == 0);
93 static errcode_t test_memalign(unsigned long align)
98 retval = ext2fs_get_memalign(32, align, &ptr);
99 if (!retval && !isaligned(ptr, align))
102 printf("tst_memliagn(%lu): %s\n", align,
103 retval ? error_message(retval) : "OK");
107 int main(int argc, char **argv)
111 if (test_memalign(4))
113 if (test_memalign(32))
115 if (test_memalign(1024))
117 if (test_memalign(4096))