public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Dipak Gaigole <dipakgaigole@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
Date: Wed, 07 Dec 2016 22:22:00 -0000	[thread overview]
Message-ID: <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw@mail.gmail.com> (raw)
In-Reply-To: <a26c3edd-8221-12e3-9bc5-c03c7b13bca1@redhat.com>

>> 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

  reply	other threads:[~2016-12-07 22:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 20:23 Dipak Gaigole
2016-12-07 20:34 ` Jeffrey Altman
2016-12-07 21:03 ` Dipak Gaigole
2016-12-07 21:08 ` Eric Blake
2016-12-07 22:22   ` Dipak Gaigole [this message]
2016-12-07 23:06     ` Eric Blake
2016-12-07 23:52       ` Dipak Gaigole
2016-12-08 12:35         ` Dipak Gaigole
2016-12-08 18:50           ` Andrey Repin
     [not found]             ` <CADs2-=R_NxbDNom1MDyyBYgtCfifQ3V-D4jy2wNkHb7fUv0Org@mail.gmail.com>
2016-12-09  7:24               ` Dipak Gaigole
2016-12-09  8:42                 ` Csaba Raduly
2016-12-12  9:12                   ` Dipak Gaigole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw@mail.gmail.com' \
    --to=dipakgaigole@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).