gbranden pushed a commit to branch master
in repository groff.
commit 99aef391f860ccfcaceff95bb3e631dc58edc12c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 18:36:57 2026 -0500
Refactor: migrate putenv(3) -> setenv(3) (2c/3).
* src/roff/groff/groff.cpp: Refactor: migrate from putenv(3) to
setenv(3) (3/4). Drop global pointer variable `groff_bin_path`.
(main): Stop initially populating `newpath` local variable with
"PATH=" in favor of straightforward call to `xsetenv()` with `PATH`
string literal and contents of `newpath` groff string as arguments.
Because, unlike putenv(3), setenv(3) makes its own copies of its C
string operands, we no longer need to reserve statically allocated
storage for them to keep them from going out of scope.
(xexit): Stop free(3)ing abandoned variable `groff_bin_path`.
---
ChangeLog | 13 +++++++++++++
src/roff/groff/groff.cpp | 7 ++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7c655ba3f..527a88559 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2026-03-15 G. Branden Robinson <[email protected]>
+
+ * src/roff/groff/groff.cpp: Refactor: migrate from putenv(3) to
+ setenv(3) (3/4). Drop global pointer variable `groff_bin_path`.
+ (main): Stop initially populating `newpath` local variable with
+ "PATH=" in favor of straightforward call to `xsetenv()` with
+ `PATH` string literal and contents of `newpath` groff string as
+ arguments. Because, unlike putenv(3), setenv(3) makes its own
+ copies of its C string operands, we no longer need to reserve
+ statically allocated storage for them to keep them from going
+ out of scope.
+ (xexit): Stop free(3)ing abandoned variable `groff_bin_path`.
+
2026-03-15 G. Branden Robinson <[email protected]>
* src/roff/groff/groff.cpp: Refactor: migrate from putenv(3) to
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index b542fa08a..2a2bfded4 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -108,7 +108,6 @@ char *spooler = 0 /* nullptr */;
char *postdriver = 0 /* nullptr */;
char *predriver = 0 /* nullptr */;
bool need_postdriver = true;
-char *groff_bin_path = 0 /* nullptr */;
possible_command commands[NCOMMANDS];
@@ -147,7 +146,6 @@ static void xexit(int status) {
free(spooler);
free(predriver);
free(postdriver);
- free(groff_bin_path);
exit(status);
}
@@ -539,7 +537,7 @@ int main(int argc, char **argv)
char *path = getenv("PATH");
xsetenv("GROFF_PATH__", path, 1 /* overwrite */);
char *binpath = getenv("GROFF_BIN_PATH");
- string newpath = "PATH=";
+ string newpath;
if ((binpath != 0 /* nullptr */ && (*binpath != '\0')))
newpath += binpath;
else {
@@ -550,8 +548,7 @@ int main(int argc, char **argv)
newpath += path;
}
newpath += '\0';
- groff_bin_path = xstrdup(newpath.contents());
- xputenv(groff_bin_path);
+ xsetenv("PATH", newpath.contents(), 1 /* overwrite */);
}
if (Vflag)
print_commands(Vflag == 1 ? stdout : stderr);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit