public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
Date: Wed, 07 Dec 2016 23:06:00 -0000	[thread overview]
Message-ID: <6e5968a1-a667-f911-fbec-f83e4ef34608@redhat.com> (raw)
In-Reply-To: <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1981 bytes --]

On 12/07/2016 04:22 PM, Dipak Gaigole wrote:

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

If you want to convert a POSIX name to the corresponding Windows name,
chdir() and getcwd() is not the best approach; and
chdir()/GetCurrentDirectory() is the wrong approach.  Instead, either
call out to the 'cygpath' utility, or use the cygwin_conv_path() API
(https://cygwin.com/cygwin-api/func-cygwin-conv-path.html) (which is
what 'cygpath' uses under the hood).

> 
> So in this situation, is it possible to get the cwd value as
> "/cygdrive/c/temp/appdir/bin" using some cygwin API?

No, it is generally not possible to get the POSIX path to anything in
the cygwin root (/) tree to be prefixed by the /cygdrive prefix. The
/cygdrive prefix exists solely to resolve paths that are outside of /,
so paths inside that tree don't need the /cygdrive prefix.

But you seem to be asking the wrong question.  If the only reason you
want a "/cygdrive/c" prefix is so that you can supply textual conversion
of "/cygdrive/c" to "c:\", then it seems like your question is really
"how do I convert the POSIX path name given by getcwd() into the
corresponding Windows directory, if one exists".  Then you don't need to
do ANY post-processing of the string, because cygwin will have already
handed you the fully-converted name, by using cygwin_conv_path() correctly.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-12-07 23:06 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
2016-12-07 23:06     ` Eric Blake [this message]
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=6e5968a1-a667-f911-fbec-f83e4ef34608@redhat.com \
    --to=eblake@redhat.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).