aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-08-14 01:42:06 -0500
committerRob Landley <rob@landley.net>2012-08-14 01:42:06 -0500
commit9c1c5ecd688052c39574999a523fa95f022b69b8 (patch)
treea051a16fde13230d5e4daeac9009d4e287f2d737
parent878aca71af67b6ceae27f6129e13c809fe8e993d (diff)
downloadtoybox-9c1c5ecd688052c39574999a523fa95f022b69b8.tar.gz
Replace TOY_LIST_LEN with more generic ARRAY_LEN()
-rw-r--r--main.c9
-rw-r--r--toys.h2
2 files changed, 6 insertions, 5 deletions
diff --git a/main.c b/main.c
index f5994187..8bd0feef 100644
--- a/main.c
+++ b/main.c
@@ -17,8 +17,6 @@ struct toy_list toy_list[] = {
#include "generated/newtoys.h"
};
-#define TOY_LIST_LEN (sizeof(toy_list)/sizeof(struct toy_list))
-
// global context for this applet.
struct toy_context toys;
@@ -37,7 +35,7 @@ struct toy_list *toy_find(char *name)
// Binary search to find this applet.
- top = TOY_LIST_LEN-1;
+ top = ARRAY_LEN(toy_list)-1;
for (;;) {
int result;
@@ -90,7 +88,8 @@ void toy_init(struct toy_list *which, char *argv[])
toys.argv = argv;
if (NEED_OPTIONS && which->options) get_optflags();
else toys.optargs = argv+1;
- if (which->flags & TOYFLAG_UMASK) toys.old_umask = umask(0);
+ toys.old_umask = umask(0);
+ if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
}
// Like exec() but runs an internal toybox command instead of another file.
@@ -123,7 +122,7 @@ void toybox_main(void)
}
// Output list of applets.
- for (i=1; i<TOY_LIST_LEN; i++) {
+ for (i=1; i<ARRAY_LEN(toy_list); i++) {
int fl = toy_list[i].flags;
if (fl & TOYMASK_LOCATION) {
if (toys.argv[1]) {
diff --git a/toys.h b/toys.h
index a03ed7c5..0338077b 100644
--- a/toys.h
+++ b/toys.h
@@ -108,3 +108,5 @@ extern struct toy_context {
extern char toybuf[4096];
#define DEFINE_GLOBALS(...)
+
+#define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))