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=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 AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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.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 AT gmail DOT 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: References: From: Dipak Gaigole Date: Thu, 8 Dec 2016 02:33:41 +0530 Message-ID: Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016 To: cygwin AT cygwin DOT 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 AT W-WIN7-56 /cygdrive/c/temp $ ./test_cwd.exe chdir (/cygdrive/c/Program Files) reuturned <0> GetCurrentDirectory returned , ret = <16> getcwd returned , ret = Administrator AT W-WIN7-56 /cygdrive/c/temp $ On Thu, Dec 8, 2016 at 1:53 AM, Dipak Gaigole 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 AT windows2k16vika /cygdrive/c/src > $ cygcheck.exe -c cygwin > Cygwin Package Information > Package Version Status > cygwin 1.7.33-1 OK > > Administrator AT 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 AT windows2k16vika /cygdrive/c/src > $ cat test_cwd.c > #include > #include > #include > > #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 AT windows2k16vika /cygdrive/c/src > $ gcc -g -Wall -lKernel32 test_cwd.c -o test_cwd > > Administrator AT windows2k16vika /cygdrive/c/src > $ ./test_cwd.exe > chdir (/cygdrive/c/Program Files) reuturned <0> > GetCurrentDirectory returned , ret = <6> > getcwd returned , ret = > > Administrator AT 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