Commit Graph

13 Commits

Author SHA1 Message Date
Karel Zak 7ca122ba84 include/list: add list_entry_is_first() and list_count_entries()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak eb06d5d4b2 include/list, include/c: update and container_of()
* update container_of() to version without "const" qualifier

* use container_of() in list_entry()

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:22:35 +02:00
Karel Zak 5d74cf0092 lib/list: remove LIST_HEAD macro
* the variable definition with hidden type is always horrible, for
  example:

	  int func() {
	    LIST_HEAD(foo);
	    ...
	  }

  the more readable is:

          int func() {
            struct list_head foo;

            INIT_LIST_HEAD(&foo);
            ...
          }

* the name LIST_HEAD conflict with /usr/include/sys/queue.h

* we use it only on two places in sulogin

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:54:59 +01:00
Sami Kerola 2a0d2a8e11 include: fix compiler warnings
This change has motivation to make -Wall -pedantic compiler options to
spit a little bit less noise, which with luck will increase change to
notice real issues.

Multiple of these:

warning: ISO C forbids braced-groups within expressions [-Wpedantic]

And nearly 300 times reported:

include/c.h:75:41: warning: struct has no named members [-Wpedantic]
 #define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:35 +02:00
Karel Zak 6736192af4 include/list: add void data to the sort cmp function
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 0f23ee0c85 include: cleanup copyright headers
We use the code from include/ and lib/ on many places, so use public
domain if possible or LGPL for code copied from libs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-08 15:10:17 +01:00
Karel Zak 59da1544ce include/list: add list_last_entry()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-18 15:00:03 +01:00
Sami Liedes becd09500f include/list: fix undefined behavior in list_entry() macro
Update list_entry() macro, which is basically the same as the
container_of() macro in the kernel, to use offsetof() to fix undefined
behavior.

Caught using clang -fsanitize=undefined.

[kzak@redhat.com: port from e2fsprogs]

Signed-off-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-12-17 16:23:35 +01:00
Sami Kerola c42206e4a7 include: fix spurious list.h warnings
include/list.h:224:17: warning: ISO C forbids omitting the middle term of a ?: expression [-pedantic]
include/list.h:255:19: warning: ISO C forbids omitting the middle term of a ?: expression [-pedantic]

Compilation warned about that at least 110 times.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:51:35 +02:00
Karel Zak 7293e97a42 libmount: fix "already mounted" detection on systems with mtab
For systems with regular mtab the fs->root should be ignored in
"already mounted" heuristic.

Reported-by: Matt Burgess <matthew@linuxfromscratch.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-09 13:11:24 +01:00
Davidlohr Bueso 5b9df0280a lists: add list sorting routine
We need a list sorting function, just to mention one example user that could
benefit is the lib/tt code to sort columns.

This patch adds list_sort() which uses the Merge Sort algorithm, behaving
nicely in O(nlog(n)), heavily based on the kernel's implementation[1].  The
private data (void *priv) passed to the comparison function as been removed to
adopt a qsort(3)-like syntax, and IMHO we don't really need it anyways.

[1]: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=lib/list_sort.c;h=d7325c6b103f0be078ff3672c35c468ed35738f1;hb=HEAD

[kzak@redhat.com: - use size_t in list_sort()]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-16 12:37:07 +01:00
Karel Zak 85950b68e4 include: fix list.h ifdefs
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-14 15:49:07 +01:00
Karel Zak c391642d0f include: move shlibs/.../list.h to the include/ directory
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-03 15:20:11 +02:00