Skip to content

Commit cc7cb44

Browse files
committed
Import initial infrastructure
From libabc [1]: commit d509efe0aab8 From ccan [2] list module + dependencies: commit a7b28fafda0e [1]: git://git.kernel.org/pub/scm/linux/kernel/git/kay/libabc.git [2]: git://github.com/rustyrussell/ccan.git Signed-off-by: Dan Williams <[email protected]>
0 parents  commit cc7cb44

29 files changed

+2459
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.o
2+
.deps/
3+
.libs/
4+
Makefile
5+
Makefile.in
6+
/aclocal.m4
7+
/autom4te.cache
8+
/build-aux
9+
/config.*
10+
/configure
11+
/libtool
12+
/stamp-h1

COPYING

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.

Makefile.am

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
EXTRA_DIST =
2+
CLEANFILES =
3+
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
4+
AM_MAKEFLAGS = --no-print-directory
5+
6+
AM_CPPFLAGS = \
7+
-include $(top_builddir)/config.h \
8+
-DSYSCONFDIR=\""$(sysconfdir)"\" \
9+
-DLIBEXECDIR=\""$(libexecdir)"\" \
10+
-I${top_srcdir}/lib/ndctl \
11+
-I${top_srcdir}/lib \
12+
-I${top_srcdir}/
13+
14+
AM_CFLAGS = ${my_CFLAGS} \
15+
-fvisibility=hidden \
16+
-ffunction-sections \
17+
-fdata-sections
18+
19+
AM_LDFLAGS = \
20+
-Wl,--gc-sections \
21+
-Wl,--as-needed
22+
23+
SED_PROCESS = \
24+
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \
25+
-e 's,@VERSION\@,$(VERSION),g' \
26+
-e 's,@prefix\@,$(prefix),g' \
27+
-e 's,@exec_prefix\@,$(exec_prefix),g' \
28+
-e 's,@libdir\@,$(libdir),g' \
29+
-e 's,@includedir\@,$(includedir),g' \
30+
< $< > $@ || rm $@
31+
32+
%.pc: %.pc.in Makefile
33+
$(SED_PROCESS)
34+
35+
LIBNDCTL_CURRENT=2
36+
LIBNDCTL_REVISION=0
37+
LIBNDCTL_AGE=2
38+
39+
pkginclude_HEADERS = lib/ndctl/libndctl.h
40+
lib_LTLIBRARIES = lib/libndctl.la
41+
42+
lib_libndctl_la_SOURCES =\
43+
lib/libndctl-private.h \
44+
lib/libndctl.c
45+
46+
noinst_LIBRARIES = libccan.a
47+
libccan_a_SOURCES = \
48+
ccan/str/str.h \
49+
ccan/str/str_debug.h \
50+
ccan/str/str.c \
51+
ccan/str/debug.c \
52+
ccan/list/list.h \
53+
ccan/list/list.c \
54+
ccan/container_of/container_of.h \
55+
ccan/check_type/check_type.h \
56+
ccan/build_assert/build_assert.h
57+
58+
EXTRA_DIST += lib/libndctl.sym
59+
60+
lib_libndctl_la_LDFLAGS = $(AM_LDFLAGS) \
61+
-version-info $(LIBNDCTL_CURRENT):$(LIBNDCTL_REVISION):$(LIBNDCTL_AGE) \
62+
-Wl,--version-script=$(top_srcdir)/lib/libndctl.sym
63+
lib_libndctl_la_DEPENDENCIES = ${top_srcdir}/lib/libndctl.sym
64+
65+
pkgconfigdir = $(libdir)/pkgconfig
66+
pkgconfig_DATA = lib/libndctl.pc
67+
EXTRA_DIST += lib/libndctl.pc.in
68+
CLEANFILES += lib/libndctl.pc
69+
70+
TESTS = lib/test-libndctl
71+
72+
check_PROGRAMS = lib/test-libndctl
73+
lib_test_libndctl_SOURCES = lib/test-libndctl.c
74+
lib_test_libndctl_LDADD = lib/libndctl.la

autogen.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh -e
2+
3+
if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
4+
cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \
5+
chmod +x .git/hooks/pre-commit && \
6+
echo "Activated pre-commit hook."
7+
fi
8+
9+
autoreconf --install --symlink
10+
11+
libdir() {
12+
echo $(cd $1/$(gcc -print-multi-os-directory); pwd)
13+
}
14+
15+
args="--prefix=/usr \
16+
--sysconfdir=/etc \
17+
--libdir=$(libdir /usr/lib)"
18+
19+
echo
20+
echo "----------------------------------------------------------------"
21+
echo "Initialized build system. For a common configuration please run:"
22+
echo "----------------------------------------------------------------"
23+
echo
24+
echo "./configure CFLAGS='-g -O0' $args"
25+
echo

ccan/build_assert/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../licenses/CC0

ccan/build_assert/build_assert.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* CC0 (Public domain) - see LICENSE file for details */
2+
#ifndef CCAN_BUILD_ASSERT_H
3+
#define CCAN_BUILD_ASSERT_H
4+
5+
/**
6+
* BUILD_ASSERT - assert a build-time dependency.
7+
* @cond: the compile-time condition which must be true.
8+
*
9+
* Your compile will fail if the condition isn't true, or can't be evaluated
10+
* by the compiler. This can only be used within a function.
11+
*
12+
* Example:
13+
* #include <stddef.h>
14+
* ...
15+
* static char *foo_to_char(struct foo *foo)
16+
* {
17+
* // This code needs string to be at start of foo.
18+
* BUILD_ASSERT(offsetof(struct foo, string) == 0);
19+
* return (char *)foo;
20+
* }
21+
*/
22+
#define BUILD_ASSERT(cond) \
23+
do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
24+
25+
/**
26+
* BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
27+
* @cond: the compile-time condition which must be true.
28+
*
29+
* Your compile will fail if the condition isn't true, or can't be evaluated
30+
* by the compiler. This can be used in an expression: its value is "0".
31+
*
32+
* Example:
33+
* #define foo_to_char(foo) \
34+
* ((char *)(foo) \
35+
* + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
36+
*/
37+
#define BUILD_ASSERT_OR_ZERO(cond) \
38+
(sizeof(char [1 - 2*!(cond)]) - 1)
39+
40+
#endif /* CCAN_BUILD_ASSERT_H */

ccan/check_type/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../licenses/CC0

ccan/check_type/check_type.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* CC0 (Public domain) - see LICENSE file for details */
2+
#ifndef CCAN_CHECK_TYPE_H
3+
#define CCAN_CHECK_TYPE_H
4+
#include "config.h"
5+
6+
/**
7+
* check_type - issue a warning or build failure if type is not correct.
8+
* @expr: the expression whose type we should check (not evaluated).
9+
* @type: the exact type we expect the expression to be.
10+
*
11+
* This macro is usually used within other macros to try to ensure that a macro
12+
* argument is of the expected type. No type promotion of the expression is
13+
* done: an unsigned int is not the same as an int!
14+
*
15+
* check_type() always evaluates to 0.
16+
*
17+
* If your compiler does not support typeof, then the best we can do is fail
18+
* to compile if the sizes of the types are unequal (a less complete check).
19+
*
20+
* Example:
21+
* // They should always pass a 64-bit value to _set_some_value!
22+
* #define set_some_value(expr) \
23+
* _set_some_value((check_type((expr), uint64_t), (expr)))
24+
*/
25+
26+
/**
27+
* check_types_match - issue a warning or build failure if types are not same.
28+
* @expr1: the first expression (not evaluated).
29+
* @expr2: the second expression (not evaluated).
30+
*
31+
* This macro is usually used within other macros to try to ensure that
32+
* arguments are of identical types. No type promotion of the expressions is
33+
* done: an unsigned int is not the same as an int!
34+
*
35+
* check_types_match() always evaluates to 0.
36+
*
37+
* If your compiler does not support typeof, then the best we can do is fail
38+
* to compile if the sizes of the types are unequal (a less complete check).
39+
*
40+
* Example:
41+
* // Do subtraction to get to enclosing type, but make sure that
42+
* // pointer is of correct type for that member.
43+
* #define container_of(mbr_ptr, encl_type, mbr) \
44+
* (check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \
45+
* ((encl_type *) \
46+
* ((char *)(mbr_ptr) - offsetof(enclosing_type, mbr))))
47+
*/
48+
#if HAVE_TYPEOF
49+
#define check_type(expr, type) \
50+
((typeof(expr) *)0 != (type *)0)
51+
52+
#define check_types_match(expr1, expr2) \
53+
((typeof(expr1) *)0 != (typeof(expr2) *)0)
54+
#else
55+
#include <ccan/build_assert/build_assert.h>
56+
/* Without typeof, we can only test the sizes. */
57+
#define check_type(expr, type) \
58+
BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type))
59+
60+
#define check_types_match(expr1, expr2) \
61+
BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2))
62+
#endif /* HAVE_TYPEOF */
63+
64+
#endif /* CCAN_CHECK_TYPE_H */

ccan/container_of/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../licenses/CC0

ccan/container_of/container_of.h

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* CC0 (Public domain) - see LICENSE file for details */
2+
#ifndef CCAN_CONTAINER_OF_H
3+
#define CCAN_CONTAINER_OF_H
4+
#include <stddef.h>
5+
6+
#include "config.h"
7+
#include <ccan/check_type/check_type.h>
8+
9+
/**
10+
* container_of - get pointer to enclosing structure
11+
* @member_ptr: pointer to the structure member
12+
* @containing_type: the type this member is within
13+
* @member: the name of this member within the structure.
14+
*
15+
* Given a pointer to a member of a structure, this macro does pointer
16+
* subtraction to return the pointer to the enclosing type.
17+
*
18+
* Example:
19+
* struct foo {
20+
* int fielda, fieldb;
21+
* // ...
22+
* };
23+
* struct info {
24+
* int some_other_field;
25+
* struct foo my_foo;
26+
* };
27+
*
28+
* static struct info *foo_to_info(struct foo *foo)
29+
* {
30+
* return container_of(foo, struct info, my_foo);
31+
* }
32+
*/
33+
#define container_of(member_ptr, containing_type, member) \
34+
((containing_type *) \
35+
((char *)(member_ptr) \
36+
- container_off(containing_type, member)) \
37+
+ check_types_match(*(member_ptr), ((containing_type *)0)->member))
38+
39+
/**
40+
* container_off - get offset to enclosing structure
41+
* @containing_type: the type this member is within
42+
* @member: the name of this member within the structure.
43+
*
44+
* Given a pointer to a member of a structure, this macro does
45+
* typechecking and figures out the offset to the enclosing type.
46+
*
47+
* Example:
48+
* struct foo {
49+
* int fielda, fieldb;
50+
* // ...
51+
* };
52+
* struct info {
53+
* int some_other_field;
54+
* struct foo my_foo;
55+
* };
56+
*
57+
* static struct info *foo_to_info(struct foo *foo)
58+
* {
59+
* size_t off = container_off(struct info, my_foo);
60+
* return (void *)((char *)foo - off);
61+
* }
62+
*/
63+
#define container_off(containing_type, member) \
64+
offsetof(containing_type, member)
65+
66+
/**
67+
* container_of_var - get pointer to enclosing structure using a variable
68+
* @member_ptr: pointer to the structure member
69+
* @container_var: a pointer of same type as this member's container
70+
* @member: the name of this member within the structure.
71+
*
72+
* Given a pointer to a member of a structure, this macro does pointer
73+
* subtraction to return the pointer to the enclosing type.
74+
*
75+
* Example:
76+
* static struct info *foo_to_i(struct foo *foo)
77+
* {
78+
* struct info *i = container_of_var(foo, i, my_foo);
79+
* return i;
80+
* }
81+
*/
82+
#if HAVE_TYPEOF
83+
#define container_of_var(member_ptr, container_var, member) \
84+
container_of(member_ptr, typeof(*container_var), member)
85+
#else
86+
#define container_of_var(member_ptr, container_var, member) \
87+
((void *)((char *)(member_ptr) - \
88+
container_off_var(container_var, member)))
89+
#endif
90+
91+
/**
92+
* container_off_var - get offset of a field in enclosing structure
93+
* @container_var: a pointer to a container structure
94+
* @member: the name of a member within the structure.
95+
*
96+
* Given (any) pointer to a structure and a its member name, this
97+
* macro does pointer subtraction to return offset of member in a
98+
* structure memory layout.
99+
*
100+
*/
101+
#if HAVE_TYPEOF
102+
#define container_off_var(var, member) \
103+
container_off(typeof(*var), member)
104+
#else
105+
#define container_off_var(var, member) \
106+
((const char *)&(var)->member - (const char *)(var))
107+
#endif
108+
109+
#endif /* CCAN_CONTAINER_OF_H */

0 commit comments

Comments
 (0)