33 |
* |
* |
34 |
* - Thu Jun 13 23:50:07 2002 Added legal header |
* - Thu Jun 13 23:50:07 2002 Added legal header |
35 |
* |
* |
36 |
* $Id: mem_align.c,v 1.7 2002-06-13 22:05:09 edgomez Exp $ |
* $Id: mem_align.c,v 1.15.2.1 2003-04-27 20:50:54 edgomez Exp $ |
37 |
* |
* |
38 |
****************************************************************************/ |
****************************************************************************/ |
39 |
|
|
71 |
if ((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) { |
if ((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) { |
72 |
|
|
73 |
/* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */ |
/* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */ |
74 |
*mem_ptr = 0; |
*mem_ptr = 1; |
75 |
|
|
76 |
/* Return the mem_ptr pointer */ |
/* Return the mem_ptr pointer */ |
77 |
return (void *) mem_ptr++; |
return (void *)(mem_ptr+1); |
78 |
|
|
79 |
} |
} |
80 |
|
|
90 |
|
|
91 |
/* Align the tmp pointer */ |
/* Align the tmp pointer */ |
92 |
mem_ptr = |
mem_ptr = |
93 |
(uint8_t *) ((uint32_t) (tmp + alignment - 1) & |
(uint8_t *) ((ptr_t) (tmp + alignment - 1) & |
94 |
(~(uint32_t) (alignment - 1))); |
(~(ptr_t) (alignment - 1))); |
95 |
|
|
96 |
/* |
/* |
97 |
* Special case where malloc have already satisfied the alignment |
* Special case where malloc have already satisfied the alignment |