groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 11/35: [groff]: Slightly refactor: indirect putenv calls.


From: G. Branden Robinson
Subject: [groff] 11/35: [groff]: Slightly refactor: indirect putenv calls.
Date: Tue, 21 Jun 2022 14:26:28 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 19ebc01b2c4256925dd19286f5e32a305c6d7320
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Jun 19 04:57:26 2022 -0500

    [groff]: Slightly refactor: indirect putenv calls.
    
    * src/roff/groff/groff.cpp: Slightly refactor to indirect `putenv` calls
      through an error-checking wrapper.
    
      (xputenv): Add new function to die if `putenv()` fails.
      (main): Update call sites to use it.
---
 ChangeLog                |  7 +++++++
 src/roff/groff/groff.cpp | 15 +++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 352b614e..e4b25685 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-06-19  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/groff/groff.cpp: Slightly refactor to indirect
+       `putenv` calls through an error-checking wrapper.
+       (xputenv): Add new function to die if `putenv()` fails.
+       (main): Update call sites to use it.
+
 2022-06-19  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [groff]: Add information to diagnostic messages.
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index 6312c642..3ff886e5 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -110,6 +110,12 @@ const char *xbasename(const char *);
 void usage(FILE *stream);
 void help();
 
+static void xputenv(const char *s) {
+  if (putenv(const_cast<char *>(s)) != 0)
+    fatal("unable to write to environment: %1", strerror(errno));
+  return;
+}
+
 int main(int argc, char **argv)
 {
   program_name = argv[0];
@@ -465,8 +471,7 @@ int main(int argc, char **argv)
       e += fontpath;
     }
     e += '\0';
-    if (putenv(strsave(e.contents())))
-      fatal("putenv failed: %1", strerror(errno));
+    xputenv(strsave(e.contents()));
   }
   {
     // we save the original path in GROFF_PATH__ and put it into the
@@ -477,8 +482,7 @@ int main(int argc, char **argv)
     if (path && *path)
       e += path;
     e += '\0';
-    if (putenv(strsave(e.contents())))
-      fatal("putenv failed: %1", strerror(errno));
+    xputenv(strsave(e.contents()));
     char *binpath = getenv("GROFF_BIN_PATH");
     string f = "PATH";
     f += '=';
@@ -493,8 +497,7 @@ int main(int argc, char **argv)
       f += path;
     }
     f += '\0';
-    if (putenv(strsave(f.contents())))
-      fatal("putenv failed: %1", strerror(errno));
+    xputenv(strsave(f.contents()));
   }
   if (Vflag)
     print_commands(Vflag == 1 ? stdout : stderr);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]