Skip to content

Commit 2cb83de

Browse files
committed
replace __arraycount with ARRAY_SIZE
1 parent b74bf7f commit 2cb83de

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

include/macro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@
3737
# define HIDDEN
3838
#endif
3939

40+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
41+
4042
#endif /*!XBPS_MACRO_H*/

include/xbps_api_impl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
ARCHIVE_EXTRACT_UNLINK
4040
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | EXTRACT_FLAGS
4141

42-
#ifndef __arraycount
43-
#define __arraycount(x) (sizeof(x) / sizeof(*x))
44-
#endif
45-
4642
/**
4743
* @private
4844
*/

lib/conf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <string.h>
4343
#include <strings.h>
4444

45+
#include "macro.h"
4546
#include "xbps_api_impl.h"
4647

4748
/**
@@ -212,7 +213,7 @@ parse_option(char *line, size_t linelen, char **valp, size_t *vallen)
212213
if (*p != '=')
213214
return KEY_ERROR;
214215

215-
result = bsearch(&needle, keys, __arraycount(keys), sizeof(struct key), cmpkey);
216+
result = bsearch(&needle, keys, ARRAY_SIZE(keys), sizeof(struct key), cmpkey);
216217
if (result == NULL)
217218
return KEY_ERROR;
218219

lib/pkgdb_conversion.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
#include <stdio.h>
26+
#include <sys/stat.h>
27+
28+
#include <errno.h>
29+
#include <fcntl.h>
2730
#include <stdbool.h>
31+
#include <stdio.h>
2832
#include <stdlib.h>
2933
#include <string.h>
30-
#include <errno.h>
31-
#include <sys/stat.h>
32-
#include <fcntl.h>
3334

35+
#include "macro.h"
3436
#include "xbps_api_impl.h"
3537

3638
static int
@@ -115,7 +117,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist)
115117

116118
key = xbps_dictionary_keysym_cstring_nocopy(obj2);
117119
curobj = xbps_dictionary_get_keysym(pkgmetad, obj2);
118-
for (uint8_t i = 0; i < __arraycount(excluded); i++) {
120+
for (uint8_t i = 0; i < ARRAY_SIZE(excluded); i++) {
119121
if (strcmp(excluded[i], key) == 0) {
120122
skip = true;
121123
break;

lib/transaction_files.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
#include <stdlib.h>
3333
#include <string.h>
3434

35-
#include "xbps_api_impl.h"
35+
#include "macro.h"
3636
#include "uthash.h"
37+
#include "xbps_api_impl.h"
3738

3839
enum type {
3940
TYPE_LINK = 1,
@@ -296,7 +297,7 @@ collect_obsoletes(struct xbps_handle *xhp)
296297
/*
297298
* Make sure to not remove any symlink of root directory.
298299
*/
299-
for (uint8_t x = 0; x < __arraycount(basesymlinks); x++) {
300+
for (uint8_t x = 0; x < ARRAY_SIZE(basesymlinks); x++) {
300301
if (strcmp(item->file+1, basesymlinks[x]) == 0) {
301302
found = true;
302303
break;

0 commit comments

Comments
 (0)