gbranden pushed a commit to branch master
in repository groff.
commit 0ec2feb8b067cf26f0141878cca0b9d717441bb4
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 17:55:02 2026 -0500
Refactor: migrate putenv(3) -> setenv(3) (2b/3).
* src/roff/groff/groff.cpp: Refactor: migrate from putenv(3) to
setenv(3) (2/4). Drop global pointer variable `saved_path`.
(main): Drop local string `g` containing shell-like environment
variable assignment in favor of straightforward call to `xsetenv()`
with `GROFF_PATH__` string literal and existing `path` (populated by
`getenv("PATH")`) 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 `saved_path`.
---
ChangeLog | 13 +++++++++++++
src/roff/groff/groff.cpp | 10 +---------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8363c1046..7c655ba3f 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) (2/4). Drop global pointer variable `saved_path`.
+ (main): Drop local string `g` containing shell-like
+ environment variable assignment in favor of straightforward call
+ to `xsetenv()` with `GROFF_PATH__` string literal and existing
+ `path` (populated by `getenv("PATH")`) 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 `saved_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 5e478e0f5..b542fa08a 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 *saved_path = 0 /* nullptr */;
char *groff_bin_path = 0 /* nullptr */;
possible_command commands[NCOMMANDS];
@@ -148,7 +147,6 @@ static void xexit(int status) {
free(spooler);
free(predriver);
free(postdriver);
- free(saved_path);
free(groff_bin_path);
exit(status);
}
@@ -539,13 +537,7 @@ int main(int argc, char **argv)
// we save the original path in GROFF_PATH__ and put it into the
// environment -- troff will pick it up later.
char *path = getenv("PATH");
- string g = "GROFF_PATH__";
- g += '=';
- if ((path != 0 /* nullptr */ && (*path != '\0')))
- g += path;
- g += '\0';
- saved_path = xstrdup(g.contents());
- xputenv(saved_path);
+ xsetenv("GROFF_PATH__", path, 1 /* overwrite */);
char *binpath = getenv("GROFF_BIN_PATH");
string newpath = "PATH=";
if ((binpath != 0 /* nullptr */ && (*binpath != '\0')))
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit