1 /*
2 * Copyright (C) 2017 Red Hat, Inc.
3 *
4 * Licensed under the GNU Lesser General Public License Version 2.1
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef HY_UTIL_PRIVATE_HPP
22 #define HY_UTIL_PRIVATE_HPP
23
24 #include "hy-util.h"
25 #include <glib.h>
26
27 gboolean hy_is_glob_pattern(const char *pattern);
28
29 /**
30 * @brief Test if pattern is file path
31 *
32 * @param pattern Strig to analyze
33 * @return gboolean Return TRUE if pattern start with "/" or pattern[0] == '*' && pattern[1] == '/'
34 */
hy_is_file_pattern(const char * pattern)35 static inline gboolean hy_is_file_pattern(const char *pattern)
36 {
37 return pattern[0] == '/' || (pattern[0] == '*' && pattern[1] == '/');
38 }
39
40 // see http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetTable
41 static const unsigned char _BitCountLookup[256] =
42 {
43 # define B2(n) n, n+1, n+1, n+2
44 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
45 # define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
46 B6(0), B6(1), B6(1), B6(2)
47 };
48
49 inline size_t
map_count(Map * m)50 map_count(Map *m)
51 {
52 unsigned char *ti = m->map;
53 unsigned char *end = ti + m->size;
54 unsigned c = 0;
55
56 while (ti < end)
57 c += _BitCountLookup[*ti++];
58
59 return c;
60 }
61
62 GPtrArray *hy_packagelist_create(void);
63 int hy_packagelist_has(GPtrArray *plist, DnfPackage *pkg);
64 int mtime(const char *filename);
65
66 #endif
67