Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-12 Thread Dipak Gaigole
>
>> Agreed Andrey. But I couldn't find any API(s) which can serve my
>> requirements. And we can't afford to execute (fork+exec) tools like
>> cygpath for each getcwd call.
>> Any suggestions on improving this approach or any alternative approach
>> are always welcome.
>
> https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
>
> Note the CCP_PROC_CYGDRIVE option.
>
Yes Csaba, I had evaluated this option but we are using an older
version of cygwin (1.7.33) which doesn't have this option available :(

Thanks,
Dipak


Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-08 Thread Dipak Gaigole
> 
>  So in this situation, is it possible to get the cwd value as
>  "/cygdrive/c/temp/appdir/bin" using some cygwin API?
> >>>
> >>> No, it is generally not possible to get the POSIX path to anything in
> >>> the cygwin root (/) tree to be prefixed by the /cygdrive prefix. The
> >>> /cygdrive prefix exists solely to resolve paths that are outside of /,
> >>> so paths inside that tree don't need the /cygdrive prefix.
> >>>
> >> This path is also displayed to the enduser at different places. So our
> >> requirement is to always get a path in the /cygdrive/ prefix format
> >> irrespective of whether it is inside the cygwin root (/) or outside of
> >> /.
>
> > I think this can be achieved by getcwd () +
> > cygwin_conv_path(CCP_POSIX_TO_WIN_A,...) and converting the windows
> > style path to /cygdrive/ prefix format.
>
> No, this is wrong approach.
> Do not do manual path manipulation, it WILL fail.
> Always use corrsponding conversion tools provided by Cygwin.

Agreed Andrey. But I couldn't find any API(s) which can serve my
requirements. And we can't afford to execute (fork+exec) tools like
cygpath for each getcwd call.
Any suggestions on improving this approach or any alternative approach
are always welcome.

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



Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-08 Thread Dipak Gaigole
>>>
>>> So in this situation, is it possible to get the cwd value as
>>> "/cygdrive/c/temp/appdir/bin" using some cygwin API?
>>
>> No, it is generally not possible to get the POSIX path to anything in
>> the cygwin root (/) tree to be prefixed by the /cygdrive prefix. The
>> /cygdrive prefix exists solely to resolve paths that are outside of /,
>> so paths inside that tree don't need the /cygdrive prefix.
>>
> This path is also displayed to the enduser at different places. So our
> requirement is to always get a path in the /cygdrive/ prefix format
> irrespective of whether it is inside the cygwin root (/) or outside of
> /.

I think this can be achieved by getcwd () +
cygwin_conv_path(CCP_POSIX_TO_WIN_A,...) and converting the windows
style path to /cygdrive/ prefix format.

Thanks Eric for the pointers :)

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



Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-07 Thread Dipak Gaigole
>>
>> So in this situation, is it possible to get the cwd value as
>> "/cygdrive/c/temp/appdir/bin" using some cygwin API?
>
> No, it is generally not possible to get the POSIX path to anything in
> the cygwin root (/) tree to be prefixed by the /cygdrive prefix. The
> /cygdrive prefix exists solely to resolve paths that are outside of /,
> so paths inside that tree don't need the /cygdrive prefix.
>
This path is also displayed to the enduser at different places. So our
requirement is to always get a path in the /cygdrive/ prefix format
irrespective of whether it is inside the cygwin root (/) or outside of
/.

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



Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-07 Thread Dipak Gaigole
>> 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  .
12/08/2016  03:24 AM  ..
12/08/2016  03:18 AM  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 , ret = <18>
getcwd returned , ret = 

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



Re: Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-07 Thread Dipak Gaigole
> 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 , ret = 

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



On Thu, Dec 8, 2016 at 1:53 AM, Dipak Gaigole <dipakgaig...@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  VersionStatus
> 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 
> #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@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 , ret = 
>
> 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



Problem with chdir and GetCurrentDirectory on Windows 2016

2016-12-07 Thread Dipak Gaigole
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  VersionStatus
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 
#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@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 , ret = <6>
getcwd returned , ret = 

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



libtermcap.a in cygwin 1.7.7.1

2010-10-01 Thread Dipak Gaigole
Hello,

Recently I had uninstalled my previous version of cygwin (1.5.24) and
did a fresh install of latest cygwin (1.7.7.1)

When I tried to recompile my code it failed because of libtermcap.a
not found. This termcap library is needed by my code.

Further investigation shows that this library is missing from this
latest cygwin installer package.

As far as I know, the termcap library is provided under terminfo or
the older termcap cygwin package.

During my installation, I had included all the devel packages.

#
administra...@engwin03-64dev1 ~
$ cygcheck -c cygwin
Cygwin Package Information
Package Version Status
cygwin 1.7.7-1 OK

administra...@engwin03-64dev1 ~
$ cygcheck -c | egrep ncurses|terminfo|termcap
libncurses-devel 5.7-18 OK
libncurses10 5.7-18 OK
libncurses8 5.5-10 OK
libncurses9 5.7-16 OK
libncursesw-devel 5.7-18 OK
libncursesw10 5.7-18 OK
ncurses 5.7-18 OK
ncurses-demo 5.7-18 OK
ncursesw 5.7-18 OK
ncursesw-demo 5.7-18 OK
termcap 5.7_20091114-14 OK
terminfo 5.7_20091114-14 OK
terminfo0 5.5_20061104-12 OK

administra...@engwin03-64dev1 ~
$
#

Does anyone has faced similar issue?

Meanwhile I am downloading the latest cygwin 1.7.7.1 source code and
planning to recompile it.

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