Patch to 'getcwd()'.

Sergei Organov osv at javad.ru
Mon Nov 27 17:33:57 UTC 2000


Hello,

Below is a patch to 'getcwd()'. It ensures _closedir(dir) is called even on
error exit from the routine.

BR,
Sergei Organov.

Index: getcwd.c
===================================================================
RCS file: /var/local/cvsroot/oar/rtems/c/src/lib/libc/getcwd.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- getcwd.c	2000/11/17 13:05:39	1.1.1.1
+++ getcwd.c	2000/11/27 17:23:54	1.2
@@ -74,7 +74,7 @@
      size_t size;
 {
   register struct dirent *dp;
-  register DIR *dir;
+  register DIR *dir = 0;
   register dev_t dev;
   register ino_t ino;
   register int first;
@@ -254,6 +254,7 @@
       bpt -= strlen (dp->d_name);
       bcopy (dp->d_name, bpt, strlen (dp->d_name));
       (void) _closedir (dir);
+      dir = 0;
 
       /* Truncate any file name. */
       *bup = '\0';
@@ -271,6 +272,8 @@
   /* FALLTHROUGH */
 
 err:
+  if(dir)
+    (void) _closedir (dir);
   if (ptsize)
     free (pt);
   free (up);




More information about the users mailing list