delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/12/07/16:08:41

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=TSOB
ocsq2f+y9wGGr5gS1ce4MzQXOCG9wfGbLlFvbTCF8gnEyoNxfFfpbJkQuwKQifbm
22lD4oRcD+EQpP7L0VCtkpn5D0J/7UTRZRO7e/klpPsnUl38BI7hLJo5TVx3MY3d
47/9+YgAFG+s6xAV7ja8Ch3X27zgxPp7U7oYf0E=
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=8/0tCgYv5c
9JgGR1EoPEZTbs1zM=; b=XxW//AZFtiEc1caOJclh2n9yTr1f06D0q5EehMVAKb
p9VNDDe/Qpp7cQ1tTiRcxkXhMRz2rfKhA3x9ATPEBWt5iuP4+SBMpi0Ynx5f5uie
+foNM3Fot1gUPspQhEpwd0CtVs52RNwsxxGVVUOEFmyPfX3HOywP8V5gqoRW/b23
I=
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=-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
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>
From: Eric Blake <eblake AT redhat DOT com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
Message-ID: <a26c3edd-8221-12e3-9bc5-c03c7b13bca1@redhat.com>
Date: Wed, 7 Dec 2016 15:07:58 -0600
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: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g@mail.gmail.com>
X-IsSubscribed: yes

--OOM7fB9vaFbnjIoMq1fRQ01Bukka4QiWF
Content-Type: multipart/mixed; boundary="MgCGWo7whJriNeKIMIg6V8QWx9639CoCP";
 protected-headers="v1"
From: Eric Blake <eblake AT redhat DOT com>
To: cygwin AT cygwin DOT com
Message-ID: <a26c3edd-8221-12e3-9bc5-c03c7b13bca1 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>
In-Reply-To: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g AT mail DOT gmail DOT com>


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

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 AT windows2k16vika /cygdrive/c/src
> $ cat test_cwd.c
> #include <stdio.h>
> #include <unistd.h>
> #include <windows.h>

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"

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

- Raw text -


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