aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2022-04-04 11:29:58 -0500
committerRob Landley <rob@landley.net>2022-04-04 11:29:58 -0500
commitb6eb5a16dcc1b50b20cc00b504cd03beea27e17b (patch)
tree6299b31d14186e78d41f6072d21b78c0569cf01b
parent5d0fcd04ffc66bd5718c3b9877df0c71429e1ab3 (diff)
downloadtoybox-b6eb5a16dcc1b50b20cc00b504cd03beea27e17b.tar.gz
Minor cleanups, and switch lll to "long long" for 32 bit platforms.
-rw-r--r--toys/other/factor.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/toys/other/factor.c b/toys/other/factor.c
index f0e69c5d..47e1267b 100644
--- a/toys/other/factor.c
+++ b/toys/other/factor.c
@@ -2,7 +2,7 @@
*
* Copyright 2014 Rob Landley <rob@landley.net>
*
- * No standard, but it's in coreutils
+ * See https://man7.org/linux/man-pages/man1/factor.1.html
USE_FACTOR(NEWTOY(factor, 0, TOYFLAG_USR|TOYFLAG_BIN))
@@ -19,7 +19,7 @@ config FACTOR
static void factor(char *s)
{
- unsigned long long l, ll;
+ unsigned long long l, ll, lll;
for (;;) {
char *err = s;
@@ -55,9 +55,8 @@ static void factor(char *s)
}
// test odd numbers until square is > remainder or integer wrap.
- for (ll=3; ;ll += 2) {
- long lll = ll*ll;
-
+ for (ll = 3;; ll += 2) {
+ lll = ll*ll;
if (lll>l || lll<ll) {
if (l>1) printf(" %llu", l);
break;
@@ -73,14 +72,11 @@ static void factor(char *s)
void factor_main(void)
{
- if (toys.optc) {
- char **ss;
-
- for (ss = toys.optargs; *ss; ss++) factor(*ss);
- } else for (;;) {
- char *s = 0;
- size_t len = 0;
+ char *s = 0, **ss;
+ size_t len = 0;
+ if (toys.optc) for (ss = toys.optargs; *ss; ss++) factor(*ss);
+ else for (;;) {
if (-1 == getline(&s, &len, stdin)) break;
factor(s);
}