Remove sorting of privileges for security_manager
[platform/core/appfw/app-installers.git] / src / common / utils / clist_helpers.h
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_UTILS_CLIST_HELPERS_H_
6 #define COMMON_UTILS_CLIST_HELPERS_H_
7
8 #include "pkgmgr/pkgmgr_parser.h"
9
10 /* NOTE: For *_x list types in pkgmgr-info, like privileges_x or privilege_x,
11  * this macro moves the current node to the head of the list.
12  * This LISTHEAD() macro is defined in pkgmgr_parser.h in pkgmgr-info package.
13  */
14 #define PKGMGR_LIST_MOVE_NODE_TO_HEAD(list, node)                              \
15   do {                                                                         \
16     if (list) {                                                                \
17       LISTHEAD(list, node);                                                    \
18     }                                                                          \
19   } while (false)                                                              \
20
21 /*
22  * Calculates size of C style list from any of its point
23  */
24 #define PKGMGR_LIST_LEN(list)                                                  \
25   [list]() {                                                                   \
26     size_t size = 0;                                                           \
27     auto node = list;                                                          \
28     PKGMGR_LIST_MOVE_NODE_TO_HEAD(list, node);                                 \
29     while (node) {                                                             \
30       node = node->next;                                                       \
31       ++size;                                                                  \
32     }                                                                          \
33     return size;                                                               \
34   }()                                                                          \
35
36 #endif  // COMMON_UTILS_CLIST_HELPERS_H_