This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add get_current_dir_name(3)


On Sun, 2012-01-01 at 01:46 -0500, Christopher Faylor wrote:
> On Sat, Dec 31, 2011 at 08:45:07PM -0600, Yaakov (Cygwin/X) wrote:
> >+extern "C" char *
> >+get_current_dir_name (void)
> >+{
> >+  char *pwd = getenv ("PWD");
> >+  char *cwd = getcwd (NULL, 0);
> >+
> >+  if (pwd)
> >+    {
> >+      struct __stat64 pwdbuf, cwdbuf;
> >+      stat64 (pwd, &pwdbuf);
> >+      stat64 (cwd, &cwdbuf);
> >+      if (pwdbuf.st_ino == cwdbuf.st_ino)
> 
> You have to check st_dev here too don't you?

Of course.  Revised patch for winsup/cygwin attached.


Yaakov

2012-01-01  Yaakov Selkowitz  <yselkowitz@...>

	* cygwin.din (get_current_dir_name): Export.
	* path.cc (get_current_dir_name): New function.
	* posix.sgml (std-gnu): Add get_current_dir_name.
	* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.

Index: cygwin.din
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/cygwin.din,v
retrieving revision 1.250
diff -u -p -r1.250 cygwin.din
--- cygwin.din	30 Dec 2011 20:22:27 -0000	1.250
+++ cygwin.din	1 Jan 2012 07:11:31 -0000
@@ -672,6 +672,7 @@ _gcvt = gcvt SIGFE
 gcvtf SIGFE
 _gcvtf = gcvtf SIGFE
 get_avphys_pages SIGFE
+get_current_dir_name SIGFE
 get_nprocs SIGFE
 get_nprocs_conf SIGFE
 get_osfhandle SIGFE
Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.644
diff -u -p -r1.644 path.cc
--- path.cc	24 Dec 2011 13:11:34 -0000	1.644
+++ path.cc	1 Jan 2012 07:11:31 -0000
@@ -2855,6 +2855,27 @@ getwd (char *buf)
   return getcwd (buf, PATH_MAX + 1);  /*Per SuSv3!*/
 }
 
+extern "C" char *
+get_current_dir_name (void)
+{
+  char *pwd = getenv ("PWD");
+  char *cwd = getcwd (NULL, 0);
+
+  if (pwd)
+    {
+      struct __stat64 pwdbuf, cwdbuf;
+      stat64 (pwd, &pwdbuf);
+      stat64 (cwd, &cwdbuf);
+      if ((pwdbuf.st_dev == cwdbuf.st_dev) && (pwdbuf.st_ino == cwdbuf.st_ino))
+        {
+          cwd = (char *) malloc (strlen (pwd) + 1);
+          strcpy (cwd, pwd);
+        }
+    }
+
+  return cwd;
+}
+
 /* chdir: POSIX 5.2.1.1 */
 extern "C" int
 chdir (const char *in_dir)
Index: posix.sgml
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/posix.sgml,v
retrieving revision 1.73
diff -u -p -r1.73 posix.sgml
--- posix.sgml	30 Dec 2011 20:22:27 -0000	1.73
+++ posix.sgml	1 Jan 2012 07:11:32 -0000
@@ -1111,6 +1111,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008)
     fremovexattr
     fsetxattr
     get_avphys_pages
+    get_current_dir_name
     get_phys_pages
     get_nprocs
     get_nprocs_conf
Index: include/cygwin/version.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/cygwin/version.h,v
retrieving revision 1.358
diff -u -p -r1.358 version.h
--- include/cygwin/version.h	30 Dec 2011 20:22:28 -0000	1.358
+++ include/cygwin/version.h	1 Jan 2012 07:11:32 -0000
@@ -426,12 +426,13 @@ details. */
       255: Export ptsname_r.
       256: Add CW_ALLOC_DRIVE_MAP, CW_MAP_DRIVE_MAP, CW_FREE_DRIVE_MAP.
       257: Export getpt.
+      258: Export get_current_dir_name.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 257
+#define CYGWIN_VERSION_API_MINOR 258
 
      /* There is also a compatibity version number associated with the
 	shared memory regions.  It is incremented when incompatible

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]