https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80047

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |build
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2017-03-15
                 CC|                            |msebor at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot 
gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  Since the Glibc extension may not be provided by other systems I
think the portable solution is to avoid relying on it.  Since getcwd() may fail
by returning 0, the caller should also avoid assuming it succeeds.  Let me post
the following patch:

diff --git a/fixincludes/fixincl.c b/fixincludes/fixincl.c
index 6dba2f6..6e6eb21 100644
--- a/fixincludes/fixincl.c
+++ b/fixincludes/fixincl.c
@@ -1353,8 +1353,10 @@ process (void)
   if (access (pz_curr_file, R_OK) != 0)
     {
       int erno = errno;
+      char cwdbuf[MAXPATHLEN];
+      char *cwd = getcwd (cwdbuf, sizeof cwdbuf);
       fprintf (stderr, "Cannot access %s from %s\n\terror %d (%s)\n",
-               pz_curr_file, getcwd ((char *) NULL, MAXPATHLEN),
+               pz_curr_file, cwd ? cwd : "current working directory",
                erno, xstrerror (erno));
       return;
     }

Reply via email to