gbranden pushed a commit to branch master
in repository groff.
commit 46fdbfef50d86347b64fd0d2ecca90cc99315523
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 16:15:19 2026 -0500
Refactor: migrate putenv(3) -> setenv(3) (1/3).
* src/devices/grops/ps.cpp (main):
* src/devices/grops/psrm.cpp (resource_manager::output_prolog):
* src/roff/troff/input.cpp (main): Do it.
Begins fixing <https://savannah.gnu.org/bugs/?68024>.
---
ChangeLog | 10 ++++++++++
src/devices/grops/ps.cpp | 8 ++------
src/devices/grops/psrm.cpp | 9 +++------
src/roff/troff/input.cpp | 9 ++-------
4 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a74b03adb..0dd2c6d4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-03-15 G. Branden Robinson <[email protected]>
+
+ Refactor: migrate from putenv(3) to setenv(3).
+
+ * src/devices/grops/ps.cpp (main):
+ * src/devices/grops/psrm.cpp (resource_manager::output_prolog):
+ * src/roff/troff/input.cpp (main): Do it.
+
+ Begins fixing <https://savannah.gnu.org/bugs/?68024>.
+
2026-03-15 G. Branden Robinson <[email protected]>
* src/roff/groff/groff.cpp (main): Slightly refactor. Rename
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index ad5dba7d0..65cd31e4a 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -36,7 +36,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <stdint.h> // uint16_t
#include <stdio.h> // EOF, FILE, fclose(), fgets(), fileno(), fseek(),
// getc(), SEEK_SET, setbuf(), stderr, stdout
-#include <stdlib.h> // exit(), EXIT_SUCCESS, putenv(), strtol()
+#include <stdlib.h> // exit(), EXIT_SUCCESS, setenv(), strtol()
#include <string.h> // strchr(), strcmp(), strcpy(), strerror(),
// strlen(), strncmp(), strstr(), strtok()
#include <time.h> // asctime()
@@ -1911,11 +1911,7 @@ int main(int argc, char **argv)
error("ignoring invalid custom paper format '%1'", optarg);
break;
case 'P':
- env = "GROPS_PROLOGUE";
- env += '=';
- env += optarg;
- env += '\0';
- if (putenv(strsave(env.contents())) != 0)
+ if (setenv("GROPS_PROLOGUE", optarg, 1 /* overwrite */) != 0)
fatal("cannot update process environment: %1", strerror(errno));
break;
case 'v':
diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index 352f99298..284b617c2 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -24,7 +24,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <stdcountof.h>
#include <stdio.h> // EOF, FILE, fclose(), fgets(), getc(), ungetc()
-#include <stdlib.h> // getenv(), putenv(), strtoul()
+#include <stdlib.h> // getenv(), setenv(), strtoul()
#include <string.h> // strerror(), strtok()
#include "cset.h"
@@ -291,11 +291,8 @@ void resource_manager::output_prolog(ps_output &out)
out.end_line();
char *path;
if (getenv("GROPS_PROLOGUE") == 0 /* nullptr */) {
- string e = "GROPS_PROLOGUE";
- e += '=';
- e += GROPS_PROLOGUE;
- e += '\0';
- if (putenv(strsave(e.contents())) != 0)
+ if (setenv("GROPS_PROLOGUE", GROPS_PROLOGUE, 1 /* overwrite */)
+ != 0)
fatal("cannot update process environment: %1", strerror(errno));
}
char *prologue = getenv("GROPS_PROLOGUE");
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 9177868e5..c1db53c14 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -32,7 +32,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
// sprintf(), setbuf(), stderr, stdin, stdout,
// ungetc()
#include <stdlib.h> // atoi(), exit(), EXIT_FAILURE, EXIT_SUCCESS,
- // free(), getenv(), putenv(), strtol(), system()
+ // free(), getenv(), setenv(), strtol(), system()
#include <string.h> // strcpy(), strdup(), strerror()
#include <getopt.h> // getopt_long()
@@ -9912,12 +9912,7 @@ int main(int argc, char **argv)
// restore $PATH if called from groff
char* groff_path = getenv("GROFF_PATH__");
if (groff_path != 0 /* nullptr */) {
- string e = "PATH";
- e += '=';
- if (*groff_path)
- e += groff_path;
- e += '\0';
- if (putenv(strsave(e.contents())) != 0)
+ if (setenv("PATH", groff_path, 1 /* overwrite */) != 0)
fatal("cannot update process environment: %1", strerror(errno));
}
setlocale(LC_CTYPE, "");
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit