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

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:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; q=dns; s=default; b=bIeXBiP
D/xt3AiYKp341OsMTyXVQ5gTCuXqO2OcuPMHOhKLrdXmIsTDBbIizP6ncdRo1xns
S1tnaoAfJ2I6UaE5NgEWd4uKNmt7HMZUnJd838wOJchfHIMc1D+CeYCJeA2wN8cF
Fu+Rws62GdozSY0gfSTEeXV6Jb2kwJ7EOgJY=
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:mime-version:in-reply-to:references:from:date
:message-id:subject:to:content-type; s=default; bh=0VHOPwc7mNy5l
uaEUdIXDqfldO8=; b=CYozjgSTXVeK2ByRMdgnvvVFwvBnPiiE3q4zW33Y0aIaR
VcnzfRbWmZJYkAtmJaPi3wH7KZsl03k2L1b6d2o5Pycg74lPXguKOMGIjGqBY2oC
HoJ3q+v32HpH/N8psSKqawBdxbj6GcC14uga+zMGJnrc5DaeYswalMOU++Bxcg=
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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Dir, volume, H*i:sk:a26c3ed, Serial
X-HELO: mail-qk0-f195.google.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=VGE2N4MJrPqqs2XltqXFDbMvcKBm6B2udJQwPmn9rdQ=; b=cGzcGO4gSNxeeQ6TQKU7LSN5CS/GS5PVxGjNAWJM0yCF/Nrn/dtvy0qhUeN2xeHCvK Wsy7WK8DWK1P8No5K81HGXlaLT1Zd9++QlBhhMrAR67BMO8mrztknc6YP4VV0u9bynzD Or2ORYHZ3fJbss5YjO8Ekri9GTzh3LCmfQmNmw4FO0Z9PYZYAXw+LbSviqqDB5n2mcpB ir1OkIqNJWnE2dKM0F60s7ms2aYou5hGI7Hbqj0De0sQjnLRzXL6kgqlCPVgdHd8rWQl 0I7Wt761DLINoI7HAFsiPJrqN0gp4wPKK81PlTRqkjfJ96qBb6HE9EWIVaxsnNiUJTQ2 XQfA==
X-Gm-Message-State: AKaTC01b8P8BA4hE+lLSkctF5geW2nET0zAWjahfApbulll6yHL9THfTApB/WQUKycTztf2zwv5HX+qDeB9jVA==
X-Received: by 10.55.70.76 with SMTP id t73mr60589681qka.195.1481149320609; Wed, 07 Dec 2016 14:22:00 -0800 (PST)
MIME-Version: 1.0
In-Reply-To: <a26c3edd-8221-12e3-9bc5-c03c7b13bca1@redhat.com>
References: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g AT mail DOT gmail DOT com> <a26c3edd-8221-12e3-9bc5-c03c7b13bca1 AT redhat DOT com>
From: Dipak Gaigole <dipakgaigole AT gmail DOT com>
Date: Thu, 8 Dec 2016 03:52:00 +0530
Message-ID: <CADs2-=QW6AeU9a8_7c557WBfB2VgY6aNQ19E+YK-fd_jnKBMfw@mail.gmail.com>
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

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

That perfectly explains the reason behind the behavior I am facing.

> Again, DON'T use windows API calls from a cygwin program, use POSIX
> calls instead. You WANT to use getcwd() here.
>

I dig into the source code history and found that windows APIs are
used to make some use case work. Here is the simple usecase:
##############################################
C:\Temp\appdir>dir
 Volume in drive C is C_Drive
 Volume Serial Number is DE87-B7F1

 Directory of C:\Temp\appdir

12/08/2016  03:24 AM    <DIR>          .
12/08/2016  03:24 AM    <DIR>          ..
12/08/2016  03:18 AM    <DIR>          bin
11/13/2014  08:15 PM         3,247,117 cygwin1.dll
12/08/2016  03:06 AM               567 test_cwd.c
12/08/2016  03:12 AM           387,593 test_cwd.exe
               3 File(s)      3,635,277 bytes
               3 Dir(s)  27,981,082,624 bytes free

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.

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

Thanks,
Dipak

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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