While gradually converting things to C99 variable scoping, I noticed
many programs initialized values in main unnecessarily like this:
static bool some_option;
static bool some_other_option;
int
main (void)
{
/* Not necessary. */
some_option = false;
/* We can just initialize this where it is declared. */
some_other_option = true;
/* ... */
}
The 'git blame' shows those lines were written ~20 years ago, and many
programs would have newer options using static initialization.
Therefore, I felt it was safe to assume it wasn't done for the purposes
of readability and probably just the style at the time/needed to support
old compilers.
I pushed the many attached patches to prefer static initialization.
Collin
>From 300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9 Mon Sep 17 00:00:00 2001
Message-ID: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 19:52:29 -0800
Subject: [PATCH 01/24] maint: tty: prefer static initialization
* src/tty.c (main): Remove unnecessary initialization.
---
src/tty.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/tty.c b/src/tty.c
index 24c98f75c..7946fb78e 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -92,8 +92,6 @@ main (int argc, char **argv)
initialize_exit_failure (TTY_WRITE_ERROR);
atexit (close_stdout);
- silent = false;
-
while ((optc = getopt_long (argc, argv, "s", longopts, NULL)) != -1)
{
switch (optc)
--
2.53.0
>From 66d34782b96c450007d33607d3aff3dafae28ef5 Mon Sep 17 00:00:00 2001
Message-ID: <66d34782b96c450007d33607d3aff3dafae28ef5.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:00:03 -0800
Subject: [PATCH 02/24] maint: rmdir: prefer static initialization
* src/rmdir.c (main): Remove unnecessary initialization.
---
src/rmdir.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/rmdir.c b/src/rmdir.c
index 97f5f059a..fa2236cca 100644
--- a/src/rmdir.c
+++ b/src/rmdir.c
@@ -205,8 +205,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- remove_empty_parents = false;
-
int optc;
while ((optc = getopt_long (argc, argv, "pv", longopts, NULL)) != -1)
{
--
2.53.0
>From a398d52b65a40475215254a6724d0b7d325b9269 Mon Sep 17 00:00:00 2001
Message-ID: <a398d52b65a40475215254a6724d0b7d325b9269.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:03:32 -0800
Subject: [PATCH 03/24] maint: tee: prefer static initialization
* src/tee.c (main): Remove unnecessary initializations.
---
src/tee.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/tee.c b/src/tee.c
index 3adbe1804..ffd4b20ec 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -136,9 +136,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- append = false;
- ignore_interrupts = false;
-
int optc;
while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) != -1)
{
--
2.53.0
>From f009f68e3bea2beef74d6d66dab35c66a6e1431c Mon Sep 17 00:00:00 2001
Message-ID: <f009f68e3bea2beef74d6d66dab35c66a6e1431c.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:10:58 -0800
Subject: [PATCH 04/24] maint: fold: prefer static initialization
* src/fold.c (main): Remove unnecessary initializations.
---
src/fold.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/fold.c b/src/fold.c
index ff6fea247..666490f95 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -300,8 +300,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- break_spaces = have_read_stdin = false;
-
while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
{
char optargbuf[2];
--
2.53.0
>From 1197e545539026fc357f41ecb97e53fa2c08a917 Mon Sep 17 00:00:00 2001
Message-ID: <1197e545539026fc357f41ecb97e53fa2c08a917.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:14:30 -0800
Subject: [PATCH 05/24] maint: touch: prefer static initialization
* src/touch.c (main): Remove unnecessary initializations.
---
src/touch.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/touch.c b/src/touch.c
index d92a77a17..1991703b9 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -289,9 +289,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- change_times = 0;
- no_create = use_ref = false;
-
while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, NULL)) != -1)
{
switch (c)
--
2.53.0
>From 4bb3309b727ca4c5b2778ef244187e3cc664b2ce Mon Sep 17 00:00:00 2001
Message-ID: <4bb3309b727ca4c5b2778ef244187e3cc664b2ce.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:22:16 -0800
Subject: [PATCH 06/24] maint: nl: prefer static initialization
* src/nl.c (main): Remove unnecessary initialization.
---
src/nl.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/nl.c b/src/nl.c
index 1b7a08bb2..2d287b36e 100644
--- a/src/nl.c
+++ b/src/nl.c
@@ -509,8 +509,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- have_read_stdin = false;
-
while ((c = getopt_long (argc, argv, "h:b:f:v:i:pl:s:w:n:d:", longopts,
NULL))
!= -1)
--
2.53.0
>From 97b7213118d8983753c34d459a7f9d5b82b4eb85 Mon Sep 17 00:00:00 2001
Message-ID: <97b7213118d8983753c34d459a7f9d5b82b4eb85.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:29:48 -0800
Subject: [PATCH 07/24] maint: ln: prefer static initialization
* src/ln.c (main): Remove unnecessary initializations.
---
src/ln.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/ln.c b/src/ln.c
index a68e05e65..335c77150 100644
--- a/src/ln.c
+++ b/src/ln.c
@@ -532,9 +532,6 @@ main (int argc, char **argv)
atexit (close_stdin);
- symbolic_link = remove_existing_files = interactive = verbose
- = hard_dir_link = false;
-
while ((c = getopt_long (argc, argv, "bdfinrst:vFLPS:T",
long_options, NULL))
!= -1)
--
2.53.0
>From 5b29c9c04f4157e27fc52141a4c4f99b2f9b72b0 Mon Sep 17 00:00:00 2001
Message-ID: <5b29c9c04f4157e27fc52141a4c4f99b2f9b72b0.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:33:10 -0800
Subject: [PATCH 08/24] maint: head: prefer static initialization
* src/head.c (line_end): Initialize variable.
(main): Remove unnecessary initializations.
---
src/head.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/src/head.c b/src/head.c
index 704be33be..e6596ecbe 100644
--- a/src/head.c
+++ b/src/head.c
@@ -58,7 +58,7 @@ static bool presume_input_pipe;
static bool print_headers;
/* Character to split lines by. */
-static char line_end;
+static char line_end = '\n';
/* When to print the filename banners. */
enum header_mode
@@ -943,12 +943,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- have_read_stdin = false;
-
- print_headers = false;
-
- line_end = '\n';
-
if (1 < argc && argv[1][0] == '-' && c_isdigit (argv[1][1]))
{
char *a = argv[1];
--
2.53.0
>From beb939220637a6203193c333cb6d7a4355c27398 Mon Sep 17 00:00:00 2001
Message-ID: <beb939220637a6203193c333cb6d7a4355c27398.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:39:41 -0800
Subject: [PATCH 09/24] maint: chmod: prefer static initialization
* src/chmod.c (main): Remove unnecessary initializations.
---
src/chmod.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/chmod.c b/src/chmod.c
index 6dd9f0b06..8b5717270 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -494,8 +494,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- recurse = force_silent = diagnose_surprises = false;
-
while ((c = getopt_long (argc, argv,
("HLPRcfhvr::w::x::X::s::t::u::g::o::a::,::+::=::"
"0::1::2::3::4::5::6::7::"),
--
2.53.0
>From 70e4e2d43aa309e397fe689ad6c5ffefb6716516 Mon Sep 17 00:00:00 2001
Message-ID: <70e4e2d43aa309e397fe689ad6c5ffefb6716516.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:45:54 -0800
Subject: [PATCH 10/24] maint: install: prefer static initialization
* src/install.c (main): Remove unnecessary initializations.
---
src/install.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/install.c b/src/install.c
index 359eb657e..58ecfbc31 100644
--- a/src/install.c
+++ b/src/install.c
@@ -857,10 +857,6 @@ main (int argc, char **argv)
cp_option_init (&x);
- owner_name = NULL;
- group_name = NULL;
- strip_files = false;
- dir_arg = false;
umask (0);
int optc;
--
2.53.0
>From ef72d0edd299946fe5a892d334736d3965d6d9d6 Mon Sep 17 00:00:00 2001
Message-ID: <ef72d0edd299946fe5a892d334736d3965d6d9d6.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:49:40 -0800
Subject: [PATCH 11/24] maint: paste: prefer static initialization
* src/paste.c (main): Remove unnecessary initializations.
---
src/paste.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/paste.c b/src/paste.c
index e8d32f15c..bcc0b6633 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -501,9 +501,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- have_read_stdin = false;
- serial_merge = false;
-
while ((optc = getopt_long (argc, argv, "d:sz", longopts, NULL)) != -1)
{
switch (optc)
--
2.53.0
>From 82a20cd6f26303185efaad23e4a899cbb941cb84 Mon Sep 17 00:00:00 2001
Message-ID: <82a20cd6f26303185efaad23e4a899cbb941cb84.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 20:53:20 -0800
Subject: [PATCH 12/24] maint: seq: prefer static initialization
* src/seq.c (separator): Initialize variable.
(main): Remove unnecessary initializations.
---
src/seq.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/seq.c b/src/seq.c
index 29c332da0..a49a18988 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -55,7 +55,7 @@ static bool locale_ok;
static bool equal_width;
/* The string used to separate two numbers. */
-static char const *separator;
+static char const *separator = "\n";
/* The string output after all numbers have been output.
Usually "\n" or "\0". */
@@ -560,9 +560,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- equal_width = false;
- separator = "\n";
-
/* We have to handle negative numbers in the command line but this
conflicts with the command line arguments. So explicitly check first
whether the next argument looks like a negative number. */
--
2.53.0
>From 425dd90b884da8c4c9a3729d7551000cbf634a98 Mon Sep 17 00:00:00 2001
Message-ID: <425dd90b884da8c4c9a3729d7551000cbf634a98.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:01:10 -0800
Subject: [PATCH 13/24] maint: cut: prefer static initialization
* src/cut.c (main): Remove unnecessary initializations.
---
src/cut.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/src/cut.c b/src/cut.c
index 93f2b1f1f..a782788a1 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -508,12 +508,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- /* By default, all non-delimited lines are printed. */
- suppress_non_delimited = false;
-
- delim = '\0';
- have_read_stdin = false;
-
while ((optc = getopt_long (argc, argv, "b:c:d:f:nsz", longopts, NULL))
!= -1)
{
--
2.53.0
>From fea1dcadf673936a4dca2ea13713c3f9868b5366 Mon Sep 17 00:00:00 2001
Message-ID: <fea1dcadf673936a4dca2ea13713c3f9868b5366.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:05:11 -0800
Subject: [PATCH 14/24] maint: join: prefer static initialization
* src/join.c (print_pairables): Initialize variable.
(main): Remove unnecessary initializations.
---
src/join.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/join.c b/src/join.c
index 080198723..883a42005 100644
--- a/src/join.c
+++ b/src/join.c
@@ -107,7 +107,7 @@ static bool hard_LC_COLLATE;
static bool print_unpairables_1, print_unpairables_2;
/* If nonzero, print pairable lines. */
-static bool print_pairables;
+static bool print_pairables = true;
/* If nonzero, we have seen at least one unpairable line. */
static bool seen_unpairable;
@@ -1046,11 +1046,6 @@ main (int argc, char **argv)
atexit (close_stdout);
atexit (free_spareline);
- print_pairables = true;
- seen_unpairable = false;
- issued_disorder_warning[0] = issued_disorder_warning[1] = false;
- check_input_order = CHECK_ORDER_DEFAULT;
-
while ((optc = getopt_long (argc, argv, "-a:e:i1:2:j:o:t:v:z",
longopts, NULL))
!= -1)
--
2.53.0
>From 85dde4c2d9c8e929f604ead6c6534b761a0c5df8 Mon Sep 17 00:00:00 2001
Message-ID: <85dde4c2d9c8e929f604ead6c6534b761a0c5df8.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:08:43 -0800
Subject: [PATCH 15/24] maint: tac: prefer static initialization
* src/tac.c (separator, separator_ends_record, sentinel_length):
Initialize variables.
(main): Remove unnecessary initializations.
---
src/tac.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/tac.c b/src/tac.c
index 161a5ea4e..4cab99d0b 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -63,19 +63,19 @@ tac -r -s '.\|
#define WRITESIZE 8192
/* The string that separates the records of the file. */
-static char const *separator;
+static char const *separator = "\n";
/* True if we have ever read standard input. */
static bool have_read_stdin = false;
/* If true, print 'separator' along with the record preceding it
in the file; otherwise with the record following it. */
-static bool separator_ends_record;
+static bool separator_ends_record = true;
/* 0 if 'separator' is to be matched as a regular expression;
otherwise, the length of 'separator', used as a sentinel to
stop the search. */
-static size_t sentinel_length;
+static size_t sentinel_length = 1;
/* The length of a match with 'separator'. If 'sentinel_length' is 0,
'match_length' is computed every time a match succeeds;
@@ -504,10 +504,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- separator = "\n";
- sentinel_length = 1;
- separator_ends_record = true;
-
while ((optc = getopt_long (argc, argv, "brs:", longopts, NULL)) != -1)
{
switch (optc)
--
2.53.0
>From ecf3f98eec0ce8e7991fd4956374b604527c80da Mon Sep 17 00:00:00 2001
Message-ID: <ecf3f98eec0ce8e7991fd4956374b604527c80da.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:11:27 -0800
Subject: [PATCH 16/24] maint: wc: prefer static initialization
* src/wc.c (main): Remove unnecessary initializations.
---
src/wc.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/wc.c b/src/wc.c
index eb6c3d9e4..2e2a9b03c 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -813,10 +813,6 @@ main (int argc, char **argv)
posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
- print_lines = print_words = print_chars = print_bytes = false;
- print_linelength = false;
- total_lines = total_words = total_chars = total_bytes = max_line_length = 0;
-
while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1)
switch (optc)
{
--
2.53.0
>From dc0baaf4de2da367b2ac02e3d24db0c993bddcbd Mon Sep 17 00:00:00 2001
Message-ID: <dc0baaf4de2da367b2ac02e3d24db0c993bddcbd.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:18:41 -0800
Subject: [PATCH 17/24] maint: comm: prefer static initialization
* src/comm.c (only_file_1, only_file_2, both): Initialize variables.
(main): Remove unnecessary initializations.
---
src/comm.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/comm.c b/src/comm.c
index 87cd65eb5..8e671f40d 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -40,13 +40,13 @@
static bool hard_LC_COLLATE;
/* If true, print lines that are found only in file 1. */
-static bool only_file_1;
+static bool only_file_1 = true;
/* If true, print lines that are found only in file 2. */
-static bool only_file_2;
+static bool only_file_2 = true;
/* If true, print lines that are found in both files. */
-static bool both;
+static bool both = true;
/* If nonzero, we have seen at least one unpairable line. */
static bool seen_unpairable;
@@ -434,15 +434,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- only_file_1 = true;
- only_file_2 = true;
- both = true;
-
- seen_unpairable = false;
- issued_disorder_warning[0] = issued_disorder_warning[1] = false;
- check_input_order = CHECK_ORDER_DEFAULT;
- total_option = false;
-
while ((c = getopt_long (argc, argv, "123z", long_options, NULL)) != -1)
switch (c)
{
--
2.53.0
>From cc87809aae1e8df0c7ce658585a175ea089c50c7 Mon Sep 17 00:00:00 2001
Message-ID: <cc87809aae1e8df0c7ce658585a175ea089c50c7.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:22:17 -0800
Subject: [PATCH 18/24] maint: csplit: prefer static initialization
* src/csplit.c (prefix, remove_files): Initialize variables.
(main): Remove unnecessary initializations.
---
src/csplit.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/csplit.c b/src/csplit.c
index 1f0253c3c..d453afbbf 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -132,7 +132,7 @@ static bool have_read_eof = false;
static char *volatile filename_space = NULL;
/* Prefix part of output file names. */
-static char const *volatile prefix = NULL;
+static char const *volatile prefix = DEFAULT_PREFIX;
/* Suffix part of output file names. */
static char *volatile suffix = NULL;
@@ -159,7 +159,7 @@ static char **global_argv;
static bool suppress_count;
/* If true, remove output files on error. */
-static bool volatile remove_files;
+static bool volatile remove_files = true;
/* If true, remove all output files which have a zero length. */
static bool elide_empty_files;
@@ -1292,12 +1292,6 @@ main (int argc, char **argv)
atexit (close_stdout);
global_argv = argv;
- controls = NULL;
- control_used = 0;
- suppress_count = false;
- remove_files = true;
- suppress_matched = false;
- prefix = DEFAULT_PREFIX;
while ((optc = getopt_long (argc, argv, "f:b:kn:sqz", longopts, NULL))
!= -1)
--
2.53.0
>From 26c92a62c69c44e890e071a59d62bc74181b6826 Mon Sep 17 00:00:00 2001
Message-ID: <26c92a62c69c44e890e071a59d62bc74181b6826.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:24:54 -0800
Subject: [PATCH 19/24] maint: tail: prefer static initialization
* src/tail.c (count_lines, line_end): Initialize variables.
(main): Remove unnecessary initializations.
---
src/tail.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/src/tail.c b/src/tail.c
index c0d4e0329..2bc29cb5d 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -177,7 +177,7 @@ static bool reopen_inaccessible_files;
/* If true, interpret the numeric argument as the number of lines.
Otherwise, interpret it as the number of bytes. */
-static bool count_lines;
+static bool count_lines = true;
/* Whether we follow the name of each file or the file descriptor
that is initially associated with each name. */
@@ -196,7 +196,7 @@ static bool from_start;
static bool print_headers;
/* Character to split lines by. */
-static char line_end;
+static char line_end = '\n';
/* When to print the filename banners. */
enum header_mode
@@ -2376,11 +2376,6 @@ main (int argc, char **argv)
page_size = p;
}
- have_read_stdin = false;
-
- count_lines = true;
- forever = from_start = print_headers = false;
- line_end = '\n';
obsolete_option = parse_obsolete_option (argc, argv, &n_units);
argc -= obsolete_option;
argv += obsolete_option;
--
2.53.0
>From a24b3075c353df1e6c83f515061043b664b35560 Mon Sep 17 00:00:00 2001
Message-ID: <a24b3075c353df1e6c83f515061043b664b35560.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:28:40 -0800
Subject: [PATCH 20/24] maint: split: prefer static initialization
* src/split.c (outbase, infile): Initialize variables.
(main): Remove unnecessary initializations.
---
src/split.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/split.c b/src/split.c
index aca6432dd..e5fd0ae2e 100644
--- a/src/split.c
+++ b/src/split.c
@@ -66,7 +66,7 @@ static int n_open_pipes;
static bool default_SIGPIPE;
/* Base name of output files. */
-static char const *outbase;
+static char const *outbase = "x";
/* Name of output files. */
static char *outfile;
@@ -91,7 +91,7 @@ static char const *numeric_suffix_start;
static char const *additional_suffix;
/* Name of input file. May be "-". */
-static char const *infile;
+static char const *infile = "-";
/* stat buf for input file. */
static struct stat in_stat_buf;
@@ -1426,9 +1426,6 @@ main (int argc, char **argv)
/* Parse command line options. */
- infile = "-";
- outbase = "x";
-
while (true)
{
/* This is the argv-index of the option we will read next. */
--
2.53.0
>From 96e39300b1246e76765d30f8dd2bfa2d42804215 Mon Sep 17 00:00:00 2001
Message-ID: <96e39300b1246e76765d30f8dd2bfa2d42804215.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:34:03 -0800
Subject: [PATCH 21/24] maint: df: prefer static initialization
* src/df.c (human_output_opts, grand_fsu): Initialize variables.
(main): Remove unnecessary initializations.
---
src/df.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/src/df.c b/src/df.c
index 25235a237..377b59dce 100644
--- a/src/df.c
+++ b/src/df.c
@@ -69,7 +69,7 @@ static bool show_local_fs;
static bool show_listed_fs;
/* Human-readable options for output. */
-static int human_output_opts;
+static int human_output_opts = -1;
/* The units to use when printing sizes. */
static uintmax_t output_block_size;
@@ -122,7 +122,7 @@ static bool print_type;
static bool print_grand_total;
/* Grand total data. */
-static struct fs_usage grand_fsu;
+static struct fs_usage grand_fsu = { .fsu_blocksize = 1 };
/* Display modes. */
static enum
@@ -1596,17 +1596,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- fs_select_list = NULL;
- fs_exclude_list = NULL;
- show_all_fs = false;
- show_listed_fs = false;
- human_output_opts = -1;
- print_type = false;
- file_systems_processed = false;
- exit_status = EXIT_SUCCESS;
- print_grand_total = false;
- grand_fsu.fsu_blocksize = 1;
-
/* If true, use the POSIX output format. */
bool posix_format = false;
--
2.53.0
>From 6bf6d52e54ef7c155f6ff435485972b05ff99c12 Mon Sep 17 00:00:00 2001
Message-ID: <6bf6d52e54ef7c155f6ff435485972b05ff99c12.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:37:15 -0800
Subject: [PATCH 22/24] maint: sort: prefer static initialization
* src/sort.c (main): Remove unnecessary initialization.
---
src/sort.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/sort.c b/src/sort.c
index eaf06d25c..c35890ec2 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -4483,7 +4483,6 @@ main (int argc, char **argv)
thousands_sep = NON_CHAR;
}
- have_read_stdin = false;
inittables ();
{
--
2.53.0
>From 395fcca795413561dcea9291fa51a068dc0d62f2 Mon Sep 17 00:00:00 2001
Message-ID: <395fcca795413561dcea9291fa51a068dc0d62f2.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:40:44 -0800
Subject: [PATCH 23/24] maint: fmt: prefer static initialization
* src/fmt.c (prefix, max_width): Initialize variables.
(main): Remove unnecessary initializations.
---
src/fmt.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/src/fmt.c b/src/fmt.c
index bb1412057..3f76f6ec6 100644
--- a/src/fmt.c
+++ b/src/fmt.c
@@ -182,11 +182,11 @@ static bool split;
static bool uniform;
/* Prefix minus leading and trailing spaces (default ""). */
-static char const *prefix;
+static char const *prefix = "";
/* User-supplied maximum line width (default WIDTH). The only output
lines longer than this will each comprise a single word. */
-static int max_width;
+static int max_width = WIDTH;
/* Values derived from the option values. */
@@ -344,11 +344,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- crown = tagged = split = uniform = false;
- max_width = WIDTH;
- prefix = "";
- prefix_length = prefix_lead_space = prefix_full_length = 0;
-
if (argc > 1 && argv[1][0] == '-' && c_isdigit (argv[1][1]))
{
/* Old option syntax; a dash followed by one or more digits. */
--
2.53.0
>From 992da4574a850ef2dab9489344a9f8ff76f6996f Mon Sep 17 00:00:00 2001
Message-ID: <992da4574a850ef2dab9489344a9f8ff76f6996f.1771567177.git.collin.fu...@gmail.com>
In-Reply-To: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
References: <300ef2e63b72fc2778fc5bc5a6a8eb9aeee7dcc9.1771567177.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Thu, 19 Feb 2026 21:42:35 -0800
Subject: [PATCH 24/24] maint: printf: prefer static initialization
* src/printf.c (main): Remove unnecessary initialization.
---
src/printf.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/printf.c b/src/printf.c
index 8894ad27a..674dd7d07 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -700,8 +700,6 @@ main (int argc, char **argv)
atexit (close_stdout);
- exit_status = EXIT_SUCCESS;
-
posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
/* We directly parse options, rather than use parse_long_options, in
--
2.53.0