From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41660 invoked by alias); 7 Dec 2016 23:06:55 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 41398 invoked by uid 89); 7 Dec 2016 23:06:54 -0000 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 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Dec 2016 23:06:44 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2F43732 for ; Wed, 7 Dec 2016 23:06:42 +0000 (UTC) Received: from [10.10.66.24] ([10.10.66.24]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB7N6gC9018732 for ; Wed, 7 Dec 2016 18:06:42 -0500 Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016 To: cygwin@cygwin.com References: From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Message-ID: <6e5968a1-a667-f911-fbec-f83e4ef34608@redhat.com> Date: Wed, 07 Dec 2016 23:06:00 -0000 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: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="llvMBETTGHK0qxda8kOjTxuHXVt1RxsLR" X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00078.txt.bz2 --llvMBETTGHK0qxda8kOjTxuHXVt1RxsLR Content-Type: multipart/mixed; boundary="RfaV23vrj2RUkG6F6Vde4i5qGJjUJ3nrT"; protected-headers="v1" From: Eric Blake To: cygwin@cygwin.com Message-ID: <6e5968a1-a667-f911-fbec-f83e4ef34608@redhat.com> Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016 References: In-Reply-To: --RfaV23vrj2RUkG6F6Vde4i5qGJjUJ3nrT Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 1948 On 12/07/2016 04:22 PM, Dipak Gaigole wrote: > C:\Temp\appdir>.\test_cwd.exe "bin" > chdir (bin) reuturned <0> > GetCurrentDirectory returned , ret =3D <18> > getcwd returned , ret =3D >=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" Content-length: 604 -----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--