gbranden pushed a commit to branch master
in repository groff.

commit cea3e2d0f5c6b509abb0c3f69df3bfb567999a0c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 7 10:30:16 2025 -0600

    [grops,groff,troff]: Handle putenv failure better.
    
    Parallelize diagnostic messages relating to putenv(3).
    
    * src/devices/grops/ps.cpp (main):
    * src/devices/grops/psrm.cpp (resource_manager::output_prolog):
    * src/roff/groff/groff.cpp (xputenv):
    * src/roff/troff/input.cpp (main): Consistently compare `putenv()`'s
      return value to an integer literal, rather than letting it pun down to
      a Boolean.  Phrase diagnostic message consistently.  Consistently
      report `strerror(errno)` on failure.
---
 ChangeLog                  | 13 +++++++++++++
 src/devices/grops/ps.cpp   |  5 ++---
 src/devices/grops/psrm.cpp |  4 ++--
 src/roff/groff/groff.cpp   |  2 +-
 src/roff/troff/input.cpp   |  4 ++--
 5 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 159b14f75..6c667ba73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-11-07  G. Branden Robinson <[email protected]>
+
+       [grops,groff,troff]: Parallelize diagnostic messages relating to
+       putenv(3).
+
+       * src/devices/grops/ps.cpp (main):
+       * src/devices/grops/psrm.cpp (resource_manager::output_prolog):
+       * src/roff/groff/groff.cpp (xputenv):
+       * src/roff/troff/input.cpp (main): Consistently compare
+       `putenv()`'s return value to an integer literal, rather than
+       letting it pun down to a Boolean.  Phrase diagnostic message
+       consistently.  Consistently report `strerror(errno)` on failure.
+
 2025-11-07  G. Branden Robinson <[email protected]>
 
        [troff]: Improve "asciification" of more special characters.
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 747b30359..cf4eb6f2e 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -1918,9 +1918,8 @@ int main(int argc, char **argv)
       env += '=';
       env += optarg;
       env += '\0';
-      if (putenv(strsave(env.contents())))
-       fatal("unable to update process environment: %1",
-             strerror(errno));
+      if (putenv(strsave(env.contents())) != 0)
+       fatal("cannot update process environment: %1", strerror(errno));
       break;
     case 'v':
       printf("GNU grops (groff) version %s\n", Version_string);
diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index fad55e082..7d92bead8 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -297,8 +297,8 @@ void resource_manager::output_prolog(ps_output &out)
     e += '=';
     e += GROPS_PROLOGUE;
     e += '\0';
-    if (putenv(strsave(e.contents())))
-      fatal("cannot update environment: %1", strerror(errno));
+    if (putenv(strsave(e.contents())) != 0)
+      fatal("cannot update process environment: %1", strerror(errno));
   }
   char *prologue = getenv("GROPS_PROLOGUE");
   FILE *fp = font::open_resource_file(prologue, &path);
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index cb719d7cd..e38089ea5 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -139,7 +139,7 @@ static char *xstrdup(const char *s) {
 
 static void xputenv(const char *s) {
   if (putenv(const_cast<char *>(s)) != 0)
-    fatal("unable to write to environment: %1", strerror(errno));
+    fatal("cannot update process environment: %1", strerror(errno));
   return;
 }
 
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 68a924449..5e2bf3df2 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9545,8 +9545,8 @@ int main(int argc, char **argv)
     if (*groff_path)
       e += groff_path;
     e += '\0';
-    if (putenv(strsave(e.contents())))
-      fatal("putenv failed");
+    if (putenv(strsave(e.contents())) != 0)
+      fatal("cannot update process environment: %1", strerror(errno));
   }
   setlocale(LC_CTYPE, "");
   static const struct option long_options[] = {

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to