#ifndef HOST_VERSION
#include <avr/pgmspace.h>
+#define PGMS_FMT "%S"
#else
#include <stdint.h>
-
-#define printf_P printf
-#define memcmp_P memcmp
-#define strcat_P strcat
-#define strcmp_P strcmp
-#define strncmp_P strncmp
-#define strlen_P strlen
-#define vfprintf_P vfprintf
-#define vsprintf_P vsprintf
-#define PGM_P const char *
-#define PSTR(x) x
-#define PROGMEM
-
-/* XXX don't define it, it's dangerous because it can be used to read
- * an address that have not the same size */
-/* #define pgm_read_word(x) (*(x)) */
-/* #define pgm_read_byte(x) (*(x)) */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
typedef void prog_void;
typedef char prog_char;
typedef uint32_t prog_uint32_t;
typedef int64_t prog_int64_t;
+
+static inline int memcmp_P(const void *s1,
+ const prog_void *s2, unsigned n)
+{
+ return memcmp(s1, s2, n);
+}
+
+static inline void *memcpy_P(void *s1,
+ const prog_void *s2, unsigned n)
+{
+ return memcpy(s1, s2, n);
+}
+
+static inline char *strcat_P(char *s1, const prog_char *s2)
+{
+ return strcat(s1, s2);
+}
+
+static inline char *strcpy_P(char *s1, const prog_char *s2)
+{
+ return strcpy(s1, s2);
+}
+
+static inline char *strncpy_P(char *s1, const prog_char *s2,
+ unsigned n)
+{
+ return strncpy(s1, s2, n);
+}
+
+static inline int strcmp_P(const char *s1, const prog_char *s2)
+{
+ return strcmp(s1, s2);
+}
+
+static inline int strncmp_P(const char *s1, const prog_char *s2,
+ unsigned n)
+{
+ return strncmp(s1, s2, n);
+}
+
+static inline unsigned strlen_P(const prog_char *s)
+{
+ return strlen(s);
+}
+
+static inline int vfprintf_P(FILE *stream,
+ const prog_char *s, va_list ap)
+{
+ return vfprintf(stream, s, ap);
+}
+
+static inline int vsprintf_P(char *buf, const prog_char *s,
+ va_list ap)
+{
+ return vsprintf(buf, s, ap);
+}
+
+#define PGM_P const char *
+#define PSTR(x) x
+#define PROGMEM
+#define printf_P(arg...) printf(args)
+#define sprintf_P(buf, args...) sprintf(buf, args)
+#define snprintf_P(buf, n, args...) snprintf(buf, n, args)
+
+static inline uint32_t pgm_read_dword(const prog_void *x)
+{
+ return *(uint32_t *)x;
+}
+
+static inline uint16_t pgm_read_word(const prog_void *x)
+{
+ return *(uint16_t *)x;
+}
+
+static inline uint8_t pgm_read_byte(const prog_void *x)
+{
+ return *(uint8_t *)x;
+}
+
+#define PGMS_FMT "%s"
+
#endif /* HOST_VERSION */
#endif /* _AVERSIVE_PGMSPACE_H_ */