]> git.ozlabs.org Git - petitboot/commitdiff
lib: consolidate util macros in util/util.h
authorJeremy Kerr <jk@ozlabs.org>
Mon, 21 Oct 2013 03:03:17 +0000 (11:03 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 13 Nov 2013 09:20:28 +0000 (17:20 +0800)
This change groups the offsetof, container_of and ARRAY_SIZE macros in a
single header file util/util.h.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/boot.c
discover/grub2/builtins.c
discover/grub2/env.c
lib/Makefile.am
lib/array-size/array-size.h [deleted file]
lib/list/list.h
lib/pb-config/storage-test.c
lib/util/util.h [new file with mode: 0644]
test/parser/test-grub2-save-env.c

index 0237b0c962209fe65aa8b2f394946adbc24d656f..13dfe0c9781fc5be889e48e34340cbb4e952aecd 100644 (file)
@@ -9,13 +9,13 @@
 #include <fcntl.h>
 #include <sys/types.h>
 
-#include <array-size/array-size.h>
 #include <log/log.h>
 #include <pb-protocol/pb-protocol.h>
 #include <process/process.h>
 #include <system/system.h>
 #include <talloc/talloc.h>
 #include <url/url.h>
+#include <util/util.h>
 
 #include "device-handler.h"
 #include "boot.h"
index c218bc7d07155bd6426d630f26bf623f0bcb4bb6..668ed93aa10e6db074d3a7736d473f21446085dc 100644 (file)
@@ -5,7 +5,7 @@
 #include <log/log.h>
 #include <types/types.h>
 #include <talloc/talloc.h>
-#include <array-size/array-size.h>
+#include <util/util.h>
 
 #include "grub2.h"
 
index 90e9c69667abe47db82ee324c3f52052bba99648..c887c7511297c9829dab795c6cc9d84adce3401a 100644 (file)
@@ -5,7 +5,7 @@
 #include <log/log.h>
 #include <types/types.h>
 #include <talloc/talloc.h>
-#include <array-size/array-size.h>
+#include <util/util.h>
 
 #include <discover/parser.h>
 #include <discover/file.h>
index f000a2f20853324de9a90d6d02e0a472d4783276..b492d69fa5a48f60d1a856d827788bf045501b01 100644 (file)
@@ -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 (file)
index 12d59f8..0000000
+++ /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 */
-
index 0174b90e21b281edf4adba6c8bd7ef3d36b2f3e0..ad562e4cc9bedece8d299893329d084f1abddefd 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _LIST_H
 #define _LIST_H
 
+#include <util/util.h>
+
 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)
 
index 3ce58ef0a03c30b39ea44ac9b0abbfa79a58eea1..e4a0e5acce3c041534138ad06326fa9fe909507e 100644 (file)
@@ -4,7 +4,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#include <array-size/array-size.h>
+#include <util/util.h>
 
 #include "pb-config.h"
 #include "storage.h"
diff --git a/lib/util/util.h b/lib/util/util.h
new file mode 100644 (file)
index 0000000..30b472d
--- /dev/null
@@ -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 */
+
index 826963ee22a677be7c2c6befbc10dacb9bb1abb9..7f15164f0fbee68dbbf1ce9cffbbd3376bbe16cb 100644 (file)
@@ -1,7 +1,7 @@
 
 #include <string.h>
 
-#include <array-size/array-size.h>
+#include <util/util.h>
 #include <talloc/talloc.h>
 
 #include "parser-test.h"