From da04c52ab1036048520fca265cf02b61dca789e0 Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Thu, 1 Sep 2011 17:09:44 -0700 Subject: init/cutils: move list utility code to cutils from init Change-Id: I357ceee813700297d8343159f22a07659e768d41 Signed-off-by: Dima Zavin --- include/cutils/list.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ init/devices.c | 2 +- init/init.c | 2 +- init/init.h | 2 +- init/init_parser.c | 2 +- init/list.h | 51 --------------------------------------------------- init/parser.c | 1 - init/signal_handler.c | 2 +- init/ueventd_parser.c | 1 - init/util.c | 21 --------------------- libcutils/Android.mk | 1 + libcutils/list.c | 37 +++++++++++++++++++++++++++++++++++++ 12 files changed, 94 insertions(+), 79 deletions(-) create mode 100644 include/cutils/list.h delete mode 100644 init/list.h create mode 100644 libcutils/list.c diff --git a/include/cutils/list.h b/include/cutils/list.h new file mode 100644 index 0000000..eb5a3c8 --- /dev/null +++ b/include/cutils/list.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CUTILS_LIST_H_ +#define _CUTILS_LIST_H_ + +#include + +struct listnode +{ + struct listnode *next; + struct listnode *prev; +}; + +#define node_to_item(node, container, member) \ + (container *) (((char*) (node)) - offsetof(container, member)) + +#define list_declare(name) \ + struct listnode name = { \ + .next = &name, \ + .prev = &name, \ + } + +#define list_for_each(node, list) \ + for (node = (list)->next; node != (list); node = node->next) + +#define list_for_each_reverse(node, list) \ + for (node = (list)->prev; node != (list); node = node->prev) + +void list_init(struct listnode *list); +void list_add_tail(struct listnode *list, struct listnode *item); +void list_remove(struct listnode *item); + +#define list_empty(list) ((list) == (list)->next) +#define list_head(list) ((list)->next) +#define list_tail(list) ((list)->prev) + +#endif diff --git a/init/devices.c b/init/devices.c index 43d0ca3..a2f84aa 100644 --- a/init/devices.c +++ b/init/devices.c @@ -34,12 +34,12 @@ #include #include +#include #include #include "devices.h" #include "util.h" #include "log.h" -#include "list.h" #define SYSFS_PREFIX "/sys" #define FIRMWARE_DIR1 "/etc/firmware" diff --git a/init/init.c b/init/init.c index 53b8aa5..eab14f6 100755 --- a/init/init.c +++ b/init/init.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include "devices.h" #include "init.h" -#include "list.h" #include "log.h" #include "property_service.h" #include "bootchart.h" diff --git a/init/init.h b/init/init.h index 05cdfaa..2d98c7c 100644 --- a/init/init.h +++ b/init/init.h @@ -17,7 +17,7 @@ #ifndef _INIT_INIT_H #define _INIT_INIT_H -#include "list.h" +#include #include diff --git a/init/init_parser.c b/init/init_parser.c index d9d3084..fa813b9 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -27,11 +27,11 @@ #include "parser.h" #include "init_parser.h" #include "log.h" -#include "list.h" #include "property_service.h" #include "util.h" #include +#include #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include diff --git a/init/list.h b/init/list.h deleted file mode 100644 index 7b9ef32..0000000 --- a/init/list.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _INIT_LIST_H_ -#define _INIT_LIST_H_ - -#include - -struct listnode -{ - struct listnode *next; - struct listnode *prev; -}; - -#define node_to_item(node, container, member) \ - (container *) (((char*) (node)) - offsetof(container, member)) - -#define list_declare(name) \ - struct listnode name = { \ - .next = &name, \ - .prev = &name, \ - } - -#define list_for_each(node, list) \ - for (node = (list)->next; node != (list); node = node->next) - -#define list_for_each_reverse(node, list) \ - for (node = (list)->prev; node != (list); node = node->prev) - -void list_init(struct listnode *list); -void list_add_tail(struct listnode *list, struct listnode *item); -void list_remove(struct listnode *item); - -#define list_empty(list) ((list) == (list)->next) -#define list_head(list) ((list)->next) -#define list_tail(list) ((list)->prev) - -#endif diff --git a/init/parser.c b/init/parser.c index 3c2ec00..48e7aec 100644 --- a/init/parser.c +++ b/init/parser.c @@ -3,7 +3,6 @@ #include #include "parser.h" -#include "list.h" #include "log.h" #define RAW(x...) log_write(6, x) diff --git a/init/signal_handler.c b/init/signal_handler.c index f89d058..b170132 100644 --- a/init/signal_handler.c +++ b/init/signal_handler.c @@ -24,9 +24,9 @@ #include #include #include +#include #include "init.h" -#include "list.h" #include "util.h" #include "log.h" diff --git a/init/ueventd_parser.c b/init/ueventd_parser.c index 0dd8b4d..3e60df5 100644 --- a/init/ueventd_parser.c +++ b/init/ueventd_parser.c @@ -22,7 +22,6 @@ #include "ueventd_parser.h" #include "parser.h" #include "log.h" -#include "list.h" #include "util.h" static void parse_line_device(struct parse_state *state, int nargs, char **args); diff --git a/init/util.c b/init/util.c index bc24b08..fd4bee2 100755 --- a/init/util.c +++ b/init/util.c @@ -34,7 +34,6 @@ #include #include "log.h" -#include "list.h" #include "util.h" /* @@ -156,26 +155,6 @@ oops: return 0; } -void list_init(struct listnode *node) -{ - node->next = node; - node->prev = node; -} - -void list_add_tail(struct listnode *head, struct listnode *item) -{ - item->next = head; - item->prev = head->prev; - head->prev->next = item; - head->prev = item; -} - -void list_remove(struct listnode *item) -{ - item->next->prev = item->prev; - item->prev->next = item->next; -} - #define MAX_MTD_PARTITIONS 16 static struct { diff --git a/libcutils/Android.mk b/libcutils/Android.mk index e183521..3405dee 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -40,6 +40,7 @@ commonSources := \ cpu_info.c \ load_file.c \ klog.c \ + list.c \ open_memstream.c \ strdup16to8.c \ strdup8to16.c \ diff --git a/libcutils/list.c b/libcutils/list.c new file mode 100644 index 0000000..e13452d --- /dev/null +++ b/libcutils/list.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +void list_init(struct listnode *node) +{ + node->next = node; + node->prev = node; +} + +void list_add_tail(struct listnode *head, struct listnode *item) +{ + item->next = head; + item->prev = head->prev; + head->prev->next = item; + head->prev = item; +} + +void list_remove(struct listnode *item) +{ + item->next->prev = item->prev; + item->prev->next = item->next; +} -- cgit v1.1