X-Recipient: archive-cygwin@delorie.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=f2CjwMF
	+pgPoWoe51g2JCU7t2FtVa4IPfhd9skNLmKYYmNPlzvKtZnSTje04hhe8AGVEb/X
	BCvjIqkHfBaJHK7r8mSUjxr/aqwvGBzNLMtRbGTLXlanO+YPmwYVsvmQnEdnpo6o
	3pWx2QY4ceigFWFDD21aT7KwUxbFjwyi2Afg=
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=zO0yY8R5Lw7oX
	I048iQKmoiVT8k=; b=O8F3pzj7Qzx+EI8Ohvm9eZVMFvO1Xut9VvatsArEbPF+d
	5abxUeWEYkeLlke8+Rss6pronYbLAiL7IWwsPYZ4EX0BqTtvG9iEZV+rEsAW+HO5
	V29n+x6vGRKhD9vWWsZmii0bMPsPOcAyy39StY8iJfDkBgnphut9vevhvq2Rao=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:dipakga, dipakgaigole@gmail.com, U*dipakgaigole, dipakgaigolegmailcom
X-HELO: mail-qt0-f177.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=4ThVpoxg0LIcmZESOWYmXLhnes1O/iDnA47LnUWD9fw=;        b=eue+WuU6r7VhDJ2OaA70/jMabK18f8blr8/rRkgUrEfNWvX61FTvG6F93+C1VnWgGY         HAAlPSBetsj/JhyeC2Pw4RKMPW3zWoScLNVQ6X2Z5gbcTOMmX/rCvYyPt8aE+8jtbWrD         YfVcyhKlGTsOl/kdVQgFT5kJKLyM+SBekw1bVx7xtknQVUV+u1CrM5ZE41xzi+Vj4Ifu         L7Vvhs4IeKegbdGFkzWhT9MakR6ZDB1NtOj+HsLqX5FJ1zqREwl0EcDJRATv8kvb1uWe         A21O6RzK3SjbqjayFdTo8aldQECIy7Ta132oCyfEsMW2VpA+85rY7y2XED/X6/2o4f3H         hmVA==
X-Gm-Message-State: AKaTC00zxTJll6F2MKNmCvEGm3SF3Y9Ur23HYnHhKvpoAnumI3uIdrpQrkGUQ23Y4FRkDZwFXiCfjEUVNDnUBg==
X-Received: by 10.237.59.6 with SMTP id p6mr67925984qte.217.1481144621445; Wed, 07 Dec 2016 13:03:41 -0800 (PST)
MIME-Version: 1.0
In-Reply-To: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g@mail.gmail.com>
References: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g@mail.gmail.com>
From: Dipak Gaigole <dipakgaigole@gmail.com>
Date: Thu, 8 Dec 2016 02:33:41 +0530
Message-ID: <CADs2-=SCEMCeuzWq1bD3C+DYoBx56AiNQF2pkZhBQu=8nmnP=Q@mail.gmail.com>
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
To: cygwin@cygwin.com
Content-Type: text/plain; charset=UTF-8
X-IsSubscribed: yes

> GetCurrentDirectory failed with ERROR_INVALID_HANDLE.  As a result the
> buffer was not populated.  What is in dirname[] is stack garbage.

As per the documentation of GetCurrentDirectory(), "If the function
succeeds, the return value specifies the number of characters that are
written to the buffer, not including the terminating null character."
So if I am not wrong, the return value 6 indicates the number of
characters written to the buffer.

Here is the output of the same program on my windows 7 system:
Administrator@W-WIN7-56 /cygdrive/c/temp
$ ./test_cwd.exe
chdir (/cygdrive/c/Program Files) reuturned <0>
GetCurrentDirectory returned <C:\Program Files>, ret = <16>
getcwd returned </cygdrive/c/Program Files>, ret = </cygdrive/c/Program Files>

Administrator@W-WIN7-56 /cygdrive/c/temp
$



On Thu, Dec 8, 2016 at 1:53 AM, Dipak Gaigole <dipakgaigole@gmail.com> wrote:
> Hello,
>
> I am facing a very strange problem with chdir and GetCurrentDirectory.
> After calling chdir (), the call to GetCurrentDirectory () returns
> wrong value. I tested this on Windows 7 and Windows 2016. It is
> working fine on Windows 7 whereas wrong values are returned on Windows
> 2016. I guess we should see the same behavior on Windows 10 (client
> version of Windows 2016) as well.
>
> #########################################################################
> Administrator@windows2k16vika /cygdrive/c/src
> $ cygcheck.exe -c cygwin
> Cygwin Package Information
> Package              Version        Status
> cygwin               1.7.33-1       OK
>
> Administrator@windows2k16vika /cygdrive/c/src
> $ uname -a
> CYGWIN_NT-10.0-WOW6 windows2k16vika 1.7.33-2(0.280/5/3) 2014-11-13
> 15:45 i686 Cygwin
>
> Administrator@windows2k16vika /cygdrive/c/src
> $ cat test_cwd.c
> #include <stdio.h>
> #include <unistd.h>
> #include <windows.h>
>
> #define BUF_SIZE 512
>
> int main()
> {
>     int ret;
>     char *dir;
>     char dirname [BUF_SIZE];
>
>     dir = "/cygdrive/c/Program Files";
>     ret = chdir (dir);
>     fprintf (stderr, "chdir (%s) reuturned <%d>\n", dir, ret);
>
>     ret = GetCurrentDirectory(BUF_SIZE, dirname);
>     if (ret)
>         fprintf (stderr, "GetCurrentDirectory returned <%s>, ret =
> <%d>\n", dirname, ret);
>
>     dir = getcwd (dirname, BUF_SIZE);
>     fprintf (stderr, "getcwd returned <%s>, ret = <%s>\n", dirname, dir);
>
>     return 0;
> }
>
> Administrator@windows2k16vika /cygdrive/c/src
> $ gcc -g -Wall -lKernel32 test_cwd.c  -o test_cwd
>
> Administrator@windows2k16vika /cygdrive/c/src
> $ ./test_cwd.exe
> chdir (/cygdrive/c/Program Files) reuturned <0>
> GetCurrentDirectory returned <C:\Pro>, ret = <6>
> getcwd returned </cygdrive/c/Program Files>, ret = </cygdrive/c/Program Files>
>
> Administrator@windows2k16vika /cygdrive/c/src
> $
> #########################################################################
>
> Has anyone noticed such behavior on Windows 10 or 2016? Any
> suggestions, pointers?
>
> 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

