s390utils/0048-add-infrastructure-cod...

170 lines
4.4 KiB
Diff

From 1ce37d173f564b5070d1819d0f5cec4f015bcbdf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Fri, 28 Jan 2011 13:14:48 +0100
Subject: [PATCH 48/61] add infrastructure code for new features
Summary: s390-tools: Add infrastructure code for new features
Description: Add some infrastructure code from s390-tools upstream
to be used by new features:
* Add linked list implementation
* Add typedefs for replacing __uxx and __sxx datatypes
* Define S390_TOOLS_LIBDIR and S390_TOOLS_SYSCONFDIR macros
---
common.mak | 4 ++
include/list.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++
include/zt_common.h | 11 +++++
3 files changed, 119 insertions(+), 0 deletions(-)
create mode 100644 include/list.h
diff --git a/common.mak b/common.mak
index 0a7916e..625cf6c 100644
--- a/common.mak
+++ b/common.mak
@@ -42,8 +42,12 @@ else
WARNFLAGS = -W -Wall
endif
CFLAGS = $(WARNFLAGS) -O3 -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
+ -DS390_TOOLS_LIBDIR=$(TOOLS_LIBDIR) \
+ -DS390_TOOLS_SYSCONFDIR=$(SYSCONFDIR) \
$(OPT_FLAGS)
CXXFLAGS = $(WARNFLAGS) -O3 -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \
+ -DS390_TOOLS_LIBDIR=$(TOOLS_LIBDIR) \
+ -DS390_TOOLS_SYSCONFDIR=$(SYSCONFDIR) \
$(OPT_FLAGS)
export AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP INSTALL CFLAGS
diff --git a/include/list.h b/include/list.h
new file mode 100644
index 0000000..b7344ed
--- /dev/null
+++ b/include/list.h
@@ -0,0 +1,104 @@
+/*
+ * Linked list functions
+ *
+ * Copyright IBM Corp. 2001, 2010
+ * Author(s): Carsten Otte (cotte@de.ibm.com)
+ * Michael Holzheu <holzheu@linux.vnet.ibm.com>
+ */
+
+#ifndef LIST_H
+#define LIST_H
+
+#include <stddef.h>
+
+struct list {
+ struct list *next, *prev;
+};
+
+#define EMPTY_LIST(list) { &(list), &(list) }
+
+/*
+ * Add entry to begining of list
+ */
+static inline void list_add(struct list *entry, struct list *head)
+{
+ entry->next = head->next;
+ entry->next->prev = entry;
+ head->next = entry;
+ entry->prev = head;
+}
+
+/*
+ * Add entry to end of list
+ */
+static inline void list_add_end(struct list *entry, struct list *head)
+{
+ entry->prev = head->prev;
+ entry->prev->next = entry;
+ head->prev = entry;
+ entry->next = head;
+}
+
+/*
+ * Remove entry
+ */
+static inline void list_del(struct list *entry)
+{
+ entry->next->prev = entry->prev;
+ entry->prev->next = entry->next;
+ entry->next = entry;
+ entry->prev = entry;
+}
+
+/*
+ * Check if list is empty
+ */
+static inline int list_is_empty(struct list *head)
+{
+ if ((head->next == head) && (head->prev == head))
+ return 1;
+ else
+ return 0;
+}
+
+/*
+ * Initialize list
+ */
+static inline void list_init(struct list *head)
+{
+ head->next = head;
+ head->prev = head;
+}
+
+#define list_entry(ptr, type, member) ({ \
+ const typeof(((type *) 0)->member) *__member_ptr = (ptr); \
+ (type *)((char *)__member_ptr - offsetof(type, member) ); })
+
+#define list_entry_first(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+#define list_entry_next(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+#define list_entry_prev(ptr, type, member) \
+ list_entry((ptr)->prev, type, member)
+
+/*
+ * List iterators
+ */
+#define list_get(entry, type, member) \
+ ((type *)((char *)(entry)-(unsigned long)(&((type *)0)->member)))
+
+#define list_iterate(i, head, member) \
+ for (i = list_get((head)->next, typeof(*i), member); \
+ &i->member != (head); \
+ i = list_get(i->member.next, typeof(*i), member))
+
+#define list_iterate_safe(i, head, member, n) \
+ for (i = list_get((head)->next, typeof(*i), member), \
+ n = list_get(i->member.next, typeof(*i), member); \
+ &i->member != (head); \
+ i = n, \
+ n = list_get(n->member.next, typeof(*n), member))
+
+#endif /* LIST_H */
diff --git a/include/zt_common.h b/include/zt_common.h
index ba9a850..7950651 100644
--- a/include/zt_common.h
+++ b/include/zt_common.h
@@ -21,5 +21,16 @@
#endif
#define RELEASE_STRING STRINGIFY (S390_TOOLS_RELEASE)
+#define TOOLS_LIBDIR STRINGIFY (S390_TOOLS_LIBDIR)
+#define TOOLS_SYSCONFDIR STRINGIFY (S390_TOOLS_SYSCONFDIR)
+
+typedef unsigned long long u64;
+typedef signed long long s64;
+typedef unsigned int u32;
+typedef signed int s32;
+typedef unsigned short int u16;
+typedef signed short int s16;
+typedef unsigned char u8;
+typedef signed char s8;
#endif /* ZT_COMMON_H */
--
1.7.3.5