From 0b5355f17c5be3f3b565dc4bc257b7f153ac42a5 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Sun, 1 Jan 2012 18:54:25 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/cygwin.din | 1 + winsup/cygwin/include/cygwin/version.h | 3 ++- winsup/cygwin/path.cc | 21 +++++++++++++++++++++ winsup/cygwin/posix.sgml | 1 + 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e69de29bb..528e0efa2 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -0,0 +1,6 @@ +2012-01-01 Yaakov Selkowitz + + * 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. diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index e83d952a7..b46839c9a 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -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 diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index c9d29aca4..550458312 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -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 diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 0b8539065..7dc85442e 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -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) diff --git a/winsup/cygwin/posix.sgml b/winsup/cygwin/posix.sgml index 196b61c14..185964f32 100644 --- a/winsup/cygwin/posix.sgml +++ b/winsup/cygwin/posix.sgml @@ -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