delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/12/07/18:07:17

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type; q=dns; s=default; b=cGwB
lkAHEr06J2pQaUx/BvgKvk39k2mMRhmrWGsP3iMgqE5dJ4yu6/KJiHHQJ7lz6Txe
RLUpvn1FMWMLd2q8fsqGqot2Pt0dmadjshH/TA/uRRRELoX7e1FlG8prBjKVabuV
Jr35xeSFP8A88oSh/Ru0WEPd4mt2tR0wNSpFD0c=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:to:references:from:message-id:date
:mime-version:in-reply-to:content-type; s=default; bh=FiuzN+h8Pp
koe/8PK0+DcvMPCks=; b=M+IzTEJVR2cBPx9BXyIp7PIw7shIZnZDk1Il2J5/ob
JIRFcedBtI2C7jd1aRPk+CkQIw1HcuErfesRaKd0nVjMExAp5Dltts10/IQhWIF5
WZqsWiyWn39XN8xP/9EMKytSiXv0dm57PJtblPG7iP4fZ/l20jOQtF0OfKGjY6CO
4=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=textual, H*f:sk:QW6AeU9, H*MI:sk:YK-fd_j, H*i:sk:QW6AeU9
X-HELO: mx1.redhat.com
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
To: cygwin AT cygwin DOT com
References: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g AT mail DOT gmail DOT com> <a26c3edd-8221-12e3-9bc5-c03c7b13bca1 AT redhat DOT com> <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw AT mail DOT gmail DOT com>
From: Eric Blake <eblake AT redhat DOT com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
Message-ID: <6e5968a1-a667-f911-fbec-f83e4ef34608@redhat.com>
Date: Wed, 7 Dec 2016 17:06:38 -0600
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
MIME-Version: 1.0
In-Reply-To: <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw@mail.gmail.com>
X-IsSubscribed: yes

--llvMBETTGHK0qxda8kOjTxuHXVt1RxsLR
Content-Type: multipart/mixed; boundary="RfaV23vrj2RUkG6F6Vde4i5qGJjUJ3nrT";
 protected-headers="v1"
From: Eric Blake <eblake AT redhat DOT com>
To: cygwin AT cygwin DOT com
Message-ID: <6e5968a1-a667-f911-fbec-f83e4ef34608 AT redhat DOT com>
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
References: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g AT mail DOT gmail DOT com>
 <a26c3edd-8221-12e3-9bc5-c03c7b13bca1 AT redhat DOT com>
 <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw AT mail DOT gmail DOT com>
In-Reply-To: <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw AT mail DOT gmail DOT com>


--RfaV23vrj2RUkG6F6Vde4i5qGJjUJ3nrT
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

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 =3D <18>
> getcwd returned </appdir/bin>, ret =3D </appdir/bin>
>=20
> 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).

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

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


--RfaV23vrj2RUkG6F6Vde4i5qGJjUJ3nrT--

--llvMBETTGHK0qxda8kOjTxuHXVt1RxsLR
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJYSJX+AAoJEKeha0olJ0NqrHEH+QH155wHWkkEiBUTWcWUyzjm
2d4vjzVSEdKAdXxn1qFKcVsw/d1ypSTx3HHMYGtRTNaE+mHNi6FH2UYJNg7zo77V
2PfykUOHrmOIblnxNHxLYVYdwQkYn0eF1RZFbF6FrVuZuemvXPyEtlhN+gcZ7SaY
wSYhg8TjXzC2al6FN4hDGgn9iLGEKN3zXqPbYFPZsy4uGK2WUcquGwRxtMv3hlvU
7nZCUMXpA4Aiso4oCt10oxgYeFT8v9j8fmMIS8ejadD85O2/7fqWfV+9KfBImC9T
t02FP4W9pjdCiv6w6y29MTEvJRRY1wPGDnje5HuZwmPdC/0LkCMVZFF2/Dpuxoo=
=XJx2
-----END PGP SIGNATURE-----

--llvMBETTGHK0qxda8kOjTxuHXVt1RxsLR--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019