From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51697 invoked by alias); 7 Dec 2016 21:08:15 -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 51683 invoked by uid 89); 7 Dec 2016 21:08:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=WANT 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 21:08:04 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 8F0C4C0567B3 for ; Wed, 7 Dec 2016 21:08:03 +0000 (UTC) Received: from [10.10.66.44] ([10.10.66.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB7L826L000507 for ; Wed, 7 Dec 2016 16:08:03 -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: Date: Wed, 07 Dec 2016 21:08:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="OOM7fB9vaFbnjIoMq1fRQ01Bukka4QiWF" X-IsSubscribed: yes X-SW-Source: 2016-12/txt/msg00069.txt.bz2 --OOM7fB9vaFbnjIoMq1fRQ01Bukka4QiWF Content-Type: multipart/mixed; boundary="MgCGWo7whJriNeKIMIg6V8QWx9639CoCP"; protected-headers="v1" From: Eric Blake To: cygwin@cygwin.com Message-ID: Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016 References: In-Reply-To: --MgCGWo7whJriNeKIMIg6V8QWx9639CoCP Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 1662 On 12/07/2016 02:23 PM, Dipak Gaigole wrote: > Hello, >=20 > 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. > Administrator@windows2k16vika /cygdrive/c/src > $ cat test_cwd.c > #include > #include > #include Any code that does this is already suspect. >=20 > #define BUF_SIZE 512 >=20 > int main() > { > int ret; > char *dir; > char dirname [BUF_SIZE]; >=20 > dir =3D "/cygdrive/c/Program Files"; > ret =3D chdir (dir); > fprintf (stderr, "chdir (%s) reuturned <%d>\n", dir, ret); >=20 > ret =3D GetCurrentDirectory(BUF_SIZE, dirname); Again, DON'T use windows API calls from a cygwin program, use POSIX calls instead. You WANT to use getcwd() here. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --MgCGWo7whJriNeKIMIg6V8QWx9639CoCP-- --OOM7fB9vaFbnjIoMq1fRQ01Bukka4QiWF 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/ iQEcBAEBCAAGBQJYSHouAAoJEKeha0olJ0Nq2CMH/Ap8satf5MZ/K1RELtprtzC3 XCxEaTz4j6DRhPgCJAKWaZcXt2kSrldGNXjEbiAd3vwHTQyrrf1RdZlZnLLErZCG ArVrr/Km8Wj/zCxucWyUsWXvijxgz0/Mb3fBbogI42LrQNNonuukvYl5fltpn4PY cdZ2Nai01icLIRYJ4t2eQ9yA/mIJqsg9PCBG2V4evi6sJO14QeGbyWFTzYWex3t6 Yj2KHsk8/0DQvk2/K1MwKseDyWFov3s7PDhGqSNC/4qaWqyOPCubq9+GYfnSltdJ X0APcnY5BXIl9ZriDPgePzWwF6TpODNrFkv0BRSkLelxJPCstWBQL9C7EimqbiM= =Qqwr -----END PGP SIGNATURE----- --OOM7fB9vaFbnjIoMq1fRQ01Bukka4QiWF--