public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Dipak Gaigole <dipakgaigole@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Problem with chdir and GetCurrentDirectory on Windows 2016
Date: Wed, 07 Dec 2016 21:03:00 -0000	[thread overview]
Message-ID: <CADs2-=SCEMCeuzWq1bD3C+DYoBx56AiNQF2pkZhBQu=8nmnP=Q@mail.gmail.com> (raw)
In-Reply-To: <CADs2-=TCsi-vpQxa+Nhwgc6GHo734qpGh+DOYcuYo36C5r4t0g@mail.gmail.com>

> 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

  parent reply	other threads:[~2016-12-07 21:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 20:23 Dipak Gaigole
2016-12-07 20:34 ` Jeffrey Altman
2016-12-07 21:03 ` Dipak Gaigole [this message]
2016-12-07 21:08 ` Eric Blake
2016-12-07 22:22   ` Dipak Gaigole
2016-12-07 23:06     ` Eric Blake
2016-12-07 23:52       ` Dipak Gaigole
2016-12-08 12:35         ` Dipak Gaigole
2016-12-08 18:50           ` Andrey Repin
     [not found]             ` <CADs2-=R_NxbDNom1MDyyBYgtCfifQ3V-D4jy2wNkHb7fUv0Org@mail.gmail.com>
2016-12-09  7:24               ` Dipak Gaigole
2016-12-09  8:42                 ` Csaba Raduly
2016-12-12  9:12                   ` Dipak Gaigole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADs2-=SCEMCeuzWq1bD3C+DYoBx56AiNQF2pkZhBQu=8nmnP=Q@mail.gmail.com' \
    --to=dipakgaigole@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).