Commit 7442da75 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add ARM EABI defines to the va_list macros.

These are not yet tested (due to lack of ARM compiler)
parent 847f1981
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _INCLUDE_DYNARG_H_
#define _INCLUDE_DYNARG_H_
#include <stdarg.h>
#include <malloc.h>
#ifdef __x86_64__
#if defined(__x86_64__)
#include <string.h>
......@@ -66,7 +86,10 @@ do { \
#else /* __x86_64__*/
/* endif __x86_64__ */
#elif defined(__i386__)
......@@ -94,6 +117,44 @@ do { \
#define va_free(list) free(((char *)(list)) - sizeof(char *))
#endif /* __x86_64__ */
/* endif __i386__ */
#elif defined(__arm__) && defined(__ARM_EABI__)
#define va_new(list) \
do { \
char *ptr = malloc(sizeof(char *)) + sizeof(char *)*2; \
(list).__ap = ptr; \
((char **)ptr)[-1] = ptr; \
} while (0)
#define va_add(list, type, val) \
do { \
char *ptr; \
char **clist = (char **)(list).__ap; \
type tmpval = val; \
size_t size, fill; \
\
size = ((size_t)clist[-1] - (size_t)(clist)); \
if ((size & 0x7) && !(sizeof(type) & 0x7)) \
fill = 4; \
else \
fill = 0; \
clist = realloc(&clist[-2], \
size + fill + sizeof(type) + sizeof(char *)*2) + sizeof(char *)*2; \
(list).__ap = (void *)clist; \
ptr = ((char *)clist + size); \
ptr += fill; \
memcpy(ptr, &tmpval, sizeof(tmpval)); \
clist[-1] = ptr + sizeof(type); \
} while (0)
#define va_free(list) free(((char *)(list).__ap) - sizeof(char *)*2)
#endif /* defined(__arm__) && defined(__ARM_EABI__) */
#endif /* _INCLUDE_DYNARG_H_ */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment