Skip to content

Commit

Permalink
replace __arraycount with ARRAY_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncaen committed Sep 1, 2023
1 parent 349f153 commit 5bd8d35
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@
# define HIDDEN
#endif

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

#endif /*!XBPS_MACRO_H*/
4 changes: 0 additions & 4 deletions include/xbps_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
ARCHIVE_EXTRACT_UNLINK
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | EXTRACT_FLAGS

#ifndef __arraycount
#define __arraycount(x) (sizeof(x) / sizeof(*x))
#endif

/**
* @private
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <string.h>
#include <strings.h>

#include "macro.h"
#include "xbps_api_impl.h"

/**
Expand Down Expand Up @@ -212,7 +213,7 @@ parse_option(char *line, size_t linelen, char **valp, size_t *vallen)
if (*p != '=')
return KEY_ERROR;

result = bsearch(&needle, keys, __arraycount(keys), sizeof(struct key), cmpkey);
result = bsearch(&needle, keys, ARRAY_SIZE(keys), sizeof(struct key), cmpkey);
if (result == NULL)
return KEY_ERROR;

Expand Down
12 changes: 7 additions & 5 deletions lib/pkgdb_conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <sys/stat.h>

#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "macro.h"
#include "xbps_api_impl.h"

static int
Expand Down Expand Up @@ -115,7 +117,7 @@ pkgdb038(struct xbps_handle *xhp, const char *opkgdb_plist)

key = xbps_dictionary_keysym_cstring_nocopy(obj2);
curobj = xbps_dictionary_get_keysym(pkgmetad, obj2);
for (uint8_t i = 0; i < __arraycount(excluded); i++) {
for (uint8_t i = 0; i < ARRAY_SIZE(excluded); i++) {
if (strcmp(excluded[i], key) == 0) {
skip = true;
break;
Expand Down
5 changes: 3 additions & 2 deletions lib/transaction_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
#include <stdlib.h>
#include <string.h>

#include "xbps_api_impl.h"
#include "macro.h"
#include "uthash.h"
#include "xbps_api_impl.h"

enum type {
TYPE_LINK = 1,
Expand Down Expand Up @@ -296,7 +297,7 @@ collect_obsoletes(struct xbps_handle *xhp)
/*
* Make sure to not remove any symlink of root directory.
*/
for (uint8_t x = 0; x < __arraycount(basesymlinks); x++) {
for (uint8_t x = 0; x < ARRAY_SIZE(basesymlinks); x++) {
if (strcmp(item->file+1, basesymlinks[x]) == 0) {
found = true;
break;
Expand Down

0 comments on commit 5bd8d35

Please sign in to comment.