This is Unofficial EPICS BASE Doxygen Site
adjustment.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 /* src/libCom/adjustment.c */
11 
12 /* Author: Peregrine McGehee */
13 
14 #include <string.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 
18 /* Up to now epicsShareThings have been declared as imports
19  * (Appropriate for other stuff)
20  * After setting the following they will be declared as exports
21  * (Appropriate for what we implenment)
22  */
23 #include "adjustment.h"
24 
25 LIBCOM_API size_t adjustToWorstCaseAlignment(size_t size)
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 }
LIBCOM_API size_t adjustToWorstCaseAlignment(size_t size)
Definition: adjustment.c:25
Declare function adjustToWorstCaseAlignment