This is Unofficial EPICS BASE Doxygen Site
adjustment.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "adjustment.h"
+ Include dependency graph for adjustment.c:

Go to the source code of this file.

Functions

LIBCOM_API size_t adjustToWorstCaseAlignment (size_t size)
 

Function Documentation

LIBCOM_API size_t adjustToWorstCaseAlignment ( size_t  size)

returns a value larger or equal than size, that is an exact multiple of the worst case alignment for the architecture on which the routine is executed.

Definition at line 25 of file adjustment.c.

26 {
27  int align_size, adjust;
28  struct test_long_word { char c; long lw; };
29  struct test_double { char c; double d; };
30  struct test_ptr { char c; void *p; };
31  int test_long_size = sizeof(struct test_long_word) - sizeof(long);
32  int test_double_size = sizeof(struct test_double) - sizeof(double);
33  int test_ptr_size = sizeof(struct test_ptr) - sizeof(void *);
34  size_t adjusted_size = size;
35 
36  /*
37  * Use Jeff's alignment tests to determine worst case of long,
38  * double or pointer alignment requirements.
39  */
40  align_size = test_long_size > test_ptr_size ?
41  test_long_size : test_ptr_size;
42 
43  align_size = align_size > test_double_size ?
44  align_size : test_double_size;
45 
46  /*
47  * Increase the size to fit worst case alignment if not already
48  * properly aligned.
49  */
50  adjust = align_size - size%align_size;
51  if (adjust != align_size) adjusted_size += adjust;
52 
53  return (adjusted_size);
54 }