From dd8fe077022138d1f6aca7e6d6cceec61f56ce95 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 21 Oct 2013 11:03:17 +0800 Subject: [PATCH] lib: consolidate util macros in util/util.h This change groups the offsetof, container_of and ARRAY_SIZE macros in a single header file util/util.h. Signed-off-by: Jeremy Kerr --- discover/boot.c | 2 +- discover/grub2/builtins.c | 2 +- discover/grub2/env.c | 2 +- lib/Makefile.am | 3 ++- lib/array-size/array-size.h | 7 ------- lib/list/list.h | 12 ++--------- lib/pb-config/storage-test.c | 2 +- lib/util/util.h | 34 +++++++++++++++++++++++++++++++ test/parser/test-grub2-save-env.c | 2 +- 9 files changed, 43 insertions(+), 23 deletions(-) delete mode 100644 lib/array-size/array-size.h create mode 100644 lib/util/util.h diff --git a/discover/boot.c b/discover/boot.c index 0237b0c..13dfe0c 100644 --- a/discover/boot.c +++ b/discover/boot.c @@ -9,13 +9,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include "device-handler.h" #include "boot.h" diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index c218bc7..668ed93 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "grub2.h" diff --git a/discover/grub2/env.c b/discover/grub2/env.c index 90e9c69..c887c75 100644 --- a/discover/grub2/env.c +++ b/discover/grub2/env.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/Makefile.am b/lib/Makefile.am index f000a2f..b492d69 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -42,6 +42,7 @@ libpbcore_la_SOURCES = \ system/system.c \ system/system.h \ url/url.c \ - url/url.h + url/url.h \ + util/util.h MAINTAINERCLEANFILES = Makefile.in diff --git a/lib/array-size/array-size.h b/lib/array-size/array-size.h deleted file mode 100644 index 12d59f8..0000000 --- a/lib/array-size/array-size.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef ARRAY_SIZE_H -#define ARRAY_SIZE_H - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -#endif /* ARRAY_SIZE_H */ - diff --git a/lib/list/list.h b/lib/list/list.h index 0174b90..ad562e4 100644 --- a/lib/list/list.h +++ b/lib/list/list.h @@ -1,6 +1,8 @@ #ifndef _LIST_H #define _LIST_H +#include + struct list_item { struct list_item *prev, *next; }; @@ -9,16 +11,6 @@ struct list { struct list_item head; }; -#ifndef container_of -#define container_of(_ptr, _type, _member) ({ \ - const typeof( ((_type *)0)->_member ) *__mptr = (_ptr); \ - (_type *)( (char *)__mptr - offsetof(_type,_member) );}) -#endif - -#ifndef offsetof -#define offsetof(_type, _member) ((size_t) &((_type *)0)->_member) -#endif - #define list_for_each(_list, _pos) \ for (_pos = (_list)->head.next; _pos != ((_list)->head); _pos = _pos->next) diff --git a/lib/pb-config/storage-test.c b/lib/pb-config/storage-test.c index 3ce58ef..e4a0e5a 100644 --- a/lib/pb-config/storage-test.c +++ b/lib/pb-config/storage-test.c @@ -4,7 +4,7 @@ #include #include -#include +#include #include "pb-config.h" #include "storage.h" diff --git a/lib/util/util.h b/lib/util/util.h new file mode 100644 index 0000000..30b472d --- /dev/null +++ b/lib/util/util.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 IBM Corporation + * + * 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; version 2 of the License. + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef UTIL_H +#define UTIL_H + +#ifndef container_of +#define container_of(_ptr, _type, _member) ({ \ + const typeof( ((_type *)0)->_member ) *__mptr = (_ptr); \ + (_type *)( (char *)__mptr - offsetof(_type,_member) );}) +#endif + +#ifndef offsetof +#define offsetof(_type, _member) ((size_t) &((_type *)0)->_member) +#endif + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#endif /* UTIL_H */ + diff --git a/test/parser/test-grub2-save-env.c b/test/parser/test-grub2-save-env.c index 826963e..7f15164 100644 --- a/test/parser/test-grub2-save-env.c +++ b/test/parser/test-grub2-save-env.c @@ -1,7 +1,7 @@ #include -#include +#include #include #include "parser-test.h" -- 2.39.2