> GetCurrentDirectory failed with ERROR_INVALID_HANDLE. As a result the > buffer was not populated. What is in dirname[] is stack garbage.
As per the documentation of GetCurrentDirectory(), "If the function succeeds, the return value specifies the number of characters that are written to the buffer, not including the terminating null character." So if I am not wrong, the return value 6 indicates the number of characters written to the buffer. Here is the output of the same program on my windows 7 system: Administrator@W-WIN7-56 /cygdrive/c/temp $ ./test_cwd.exe chdir (/cygdrive/c/Program Files) reuturned <0> GetCurrentDirectory returned <C:\Program Files>, ret = <16> getcwd returned </cygdrive/c/Program Files>, ret = </cygdrive/c/Program Files> Administrator@W-WIN7-56 /cygdrive/c/temp $ On Thu, Dec 8, 2016 at 1:53 AM, Dipak Gaigole <dipakgaig...@gmail.com> wrote: > Hello, > > I am facing a very strange problem with chdir and GetCurrentDirectory. > After calling chdir (), the call to GetCurrentDirectory () returns > wrong value. I tested this on Windows 7 and Windows 2016. It is > working fine on Windows 7 whereas wrong values are returned on Windows > 2016. I guess we should see the same behavior on Windows 10 (client > version of Windows 2016) as well. > > ######################################################################### > Administrator@windows2k16vika /cygdrive/c/src > $ cygcheck.exe -c cygwin > Cygwin Package Information > Package Version Status > cygwin 1.7.33-1 OK > > Administrator@windows2k16vika /cygdrive/c/src > $ uname -a > CYGWIN_NT-10.0-WOW6 windows2k16vika 1.7.33-2(0.280/5/3) 2014-11-13 > 15:45 i686 Cygwin > > Administrator@windows2k16vika /cygdrive/c/src > $ cat test_cwd.c > #include <stdio.h> > #include <unistd.h> > #include <windows.h> > > #define BUF_SIZE 512 > > int main() > { > int ret; > char *dir; > char dirname [BUF_SIZE]; > > dir = "/cygdrive/c/Program Files"; > ret = chdir (dir); > fprintf (stderr, "chdir (%s) reuturned <%d>\n", dir, ret); > > ret = GetCurrentDirectory(BUF_SIZE, dirname); > if (ret) > fprintf (stderr, "GetCurrentDirectory returned <%s>, ret = > <%d>\n", dirname, ret); > > dir = getcwd (dirname, BUF_SIZE); > fprintf (stderr, "getcwd returned <%s>, ret = <%s>\n", dirname, dir); > > return 0; > } > > Administrator@windows2k16vika /cygdrive/c/src > $ gcc -g -Wall -lKernel32 test_cwd.c -o test_cwd > > Administrator@windows2k16vika /cygdrive/c/src > $ ./test_cwd.exe > chdir (/cygdrive/c/Program Files) reuturned <0> > GetCurrentDirectory returned <C:\Pro>, ret = <6> > getcwd returned </cygdrive/c/Program Files>, ret = </cygdrive/c/Program Files> > > Administrator@windows2k16vika /cygdrive/c/src > $ > ######################################################################### > > Has anyone noticed such behavior on Windows 10 or 2016? Any > suggestions, pointers? > > Thanks, > Dipak -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple