>> I am facing a very strange problem with chdir and GetCurrentDirectory. > > Not strange at all. The two are incompatible. When writing Cygwin > programs, stick to the POSIX-y interface, NOT the windows interface. > >> After calling chdir (), the call to GetCurrentDirectory () returns > > chdir() is POSIX, and the POSIX counterpart is getcwd(), which will > return the right value always. GetCurrentDirectory() is the windows > API, which may or may not have a sane value at any given time, but more > often than not does NOT match the value in getcwd(), and that is by > design - because the Cygwin notion of the working directory is more > powerful than the windows notion of the working directory, and it is > just too expensive for cygwin to try and always keep windows up-to-date > with the current directory when there are times that you can be in a > cygwin directory that has no windows counterpart. >
That perfectly explains the reason behind the behavior I am facing. > Again, DON'T use windows API calls from a cygwin program, use POSIX > calls instead. You WANT to use getcwd() here. > I dig into the source code history and found that windows APIs are used to make some use case work. Here is the simple usecase: ############################################## C:\Temp\appdir>dir Volume in drive C is C_Drive Volume Serial Number is DE87-B7F1 Directory of C:\Temp\appdir 12/08/2016 03:24 AM <DIR> . 12/08/2016 03:24 AM <DIR> .. 12/08/2016 03:18 AM <DIR> bin 11/13/2014 08:15 PM 3,247,117 cygwin1.dll 12/08/2016 03:06 AM 567 test_cwd.c 12/08/2016 03:12 AM 387,593 test_cwd.exe 3 File(s) 3,635,277 bytes 3 Dir(s) 27,981,082,624 bytes free C:\Temp\appdir>.\test_cwd.exe "bin" chdir (bin) reuturned <0> GetCurrentDirectory returned <C:\Temp\appdir\bin>, ret = <18> getcwd returned </appdir/bin>, ret = </appdir/bin> C:\Temp\appdir> ############################################## Please note that I have the cygwin1.dll in the "C:\Temp\appdir" directory. So after changing the directory to "bin", the getcwd() returned "/appdir/bin". And our requirement was to get "/cygdrive/c/temp/appdir/bin", so the GetCurrentDirectory() approach was used. So in this situation, is it possible to get the cwd value as "/cygdrive/c/temp/appdir/bin" using some cygwin API? 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