Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _ink_align_h_
00026 #define _ink_align_h_
00027
00028 # include "ink_time.h"
00029
00030 union Alias32 {
00031 uint8_t byte[4];
00032 int32_t i32;
00033 uint32_t u32;
00034 };
00035
00036 union Alias64 {
00037 uint8_t byte[8];
00038 int32_t i32[2];
00039 uint32_t u32[2];
00040 int64_t i64;
00041 uint64_t u64;
00042 ink_time_t i_time;
00043 };
00044
00045
00046
00047
00048
00049 #define INK_MIN_ALIGN 8
00050
00051 #define INK_ALIGN(size, boundary) \
00052 (((size) + ((boundary) - 1)) & ~((boundary) - 1))
00053
00054
00055 #define INK_ALIGN_DEFAULT(size) INK_ALIGN(size, INK_MIN_ALIGN)
00056
00057
00058
00059
00060 static inline void *
00061 align_pointer_forward(const void *pointer_, size_t alignment)
00062 {
00063 char *pointer = (char *) pointer_;
00064
00065
00066
00067 pointer = (char *) INK_ALIGN((ptrdiff_t) pointer, alignment);
00068
00069 return (void *) pointer;
00070 }
00071
00072
00073
00074
00075
00076 static inline void *
00077 align_pointer_forward_and_zero(const void *pointer_, size_t alignment)
00078 {
00079 char *pointer = (char *) pointer_;
00080 char *aligned = (char *) INK_ALIGN((ptrdiff_t) pointer, alignment);
00081
00082
00083
00084 while (pointer < aligned) {
00085 *pointer = 0;
00086 pointer++;
00087 }
00088
00089 return (void *) aligned;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099 #endif