[PATCH v5 13/19] libcflat: clean up libcflat.h and add string.h

Andrew Jones
2014-06-11T14:01:59Z

Use libgcc's stddef.h and stdint.h, and then remove the redundant
defines from libcflat.h. Also separate out the string function
declarations into a new file string.h. These changes have no affect
on code including libcflat.h, but are needed in order to compile an
unmodified libfdt for kvm-unit-tests using an arm cross-compiler.
While at it, add strcpy.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
---
lib/libcflat.h | 55 +++++++++++++++++++++----------------------------------
lib/string.c | 6 ++++++
lib/string.h | 15 +++++++++++++++
3 files changed, 42 insertions(+), 34 deletions(-)
create mode 100644 lib/string.h

diff --git a/lib/libcflat.h b/lib/libcflat.h
index 5939cee54890b..404560cd103e5 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -21,60 +21,47 @@
#define __LIBCFLAT_H

#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "string.h"

#define __unused __attribute__((__unused__))

#define xstr(s) xxstr(s)
#define xxstr(s) #s

-typedef unsigned char u8;
-typedef signed char s8;
-typedef unsigned short u16;
-typedef signed short s16;
-typedef unsigned u32;
-typedef signed s32;
-typedef unsigned long ulong;
-typedef unsigned long long u64;
-typedef signed long long s64;
-typedef unsigned long size_t;
-typedef _Bool bool;
-
-#define true 1
+typedef uint8_t u8;
+typedef int8_t s8;
+typedef uint16_t u16;
+typedef int16_t s16;
+typedef uint32_t u32;
+typedef int32_t s32;
+typedef uint64_t u64;
+typedef int64_t s64;
+typedef unsigned long ulong;
+
+typedef _Bool bool;
#define false 0
+#define true 1

+extern void puts(const char *s);
extern void exit(int code);

-extern unsigned long strlen(const char *buf);
-extern char *strcat(char *dest, const char *src);
-extern int strcmp(const char *a, const char *b);
-extern char *strchr(const char *s, int c);
-
extern int printf(const char *fmt, ...);
extern int snprintf(char *buf, int size, const char *fmt, ...);
extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
+extern long atol(const char *ptr);

-extern void puts(const char *s);
-
-extern void *memset(void *s, int c, size_t n);
-extern void *memcpy(void *dest, const void *src, size_t n);
-extern int memcmp(const void *s1, const void *s2, size_t n);
-extern void *memmove(void *dest, const void *src, size_t n);
-extern void *memchr(const void *s, int c, size_t n);
+void report(const char *msg_fmt, bool pass, ...);
+int report_summary(void);

-extern long atol(const char *ptr);
-#define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))
+#define ARRAY_SIZE(_a) (sizeof(_a)/sizeof((_a)[0]))

-#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

-#define NULL ((void *)0UL)
-
-void report(const char *msg_fmt, bool pass, ...);
-int report_summary(void);
-
-#define abort() exit(64) /* 129 exit status from qemu */
+#define abort() exit(64) /* 129 exit status from qemu */
#define assert(cond) \
do { \
if (!(cond)) \
diff --git a/lib/string.c b/lib/string.c
index fe90c8b1289f2..026f50252287c 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -20,6 +20,12 @@ char *strcat(char *dest, const char *src)
return dest;
}

+char *strcpy(char *dest, const char *src)
+{
+ *dest = 0;
+ return strcat(dest, src);
+}
+
int strcmp(const char *a, const char *b)
{
while (*a == *b) {
diff --git a/lib/string.h b/lib/string.h
new file mode 100644
index 0000000000000..dbab368b1b9e4
--- /dev/null
+++ b/lib/string.h
@@ -0,0 +1,15 @@
+#ifndef __STRING_H
+#define __STRING_H
+
+extern unsigned long strlen(const char *buf);
+extern char *strcat(char *dest, const char *src);
+extern char *strcpy(char *dest, const char *src);
+extern int strcmp(const char *a, const char *b);
+extern char *strchr(const char *s, int c);
+extern void *memset(void *s, int c, size_t n);
+extern void *memcpy(void *dest, const void *src, size_t n);
+extern int memcmp(const void *s1, const void *s2, size_t n);
+extern void *memmove(void *dest, const void *src, size_t n);
+extern void *memchr(const void *s, int c, size_t n);
+
+#endif /* _STRING_H */
--
1.9.3