This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Same code, same script, different results

On Thu, 23 Sep 2004, Mikael Åsberg wrote:

> Hello, I am using the latest Cygwin with all packages updated (running
> Windows XP Professional SP2) and I'm having a problem with a simple C++
> program that uses the Win32 API to scan a directory (recursively or
> non-recursively, depending on user input). The code is as follows:
> [snip]
>      if(strcmp(argv[2], "--non-recursive") == 0) {
>         recursive = false;
>         cout << "Will perform a non-recursive scan of directory "
>              << argv[1] << "." << endl;
>      } else {
>         cerr << "Ignoring unknown option " << argv[2] << "." << endl;
>      }
> [snip]

Yours was by far not a minimal testcase.  The above would have sufficed.

> If I test this program with the following bash script:
> #!/bin/bash
> echo "Performing a scan without using recursion"
> ./directory_scanner.exe c:\\coding\\cygwin\\c++\\ --non-recursive

Does your bash script have DOS line endings?  Try "d2u bashscript".

> the output is:
> Performing a scan without using recursion
> Ignoring unknown option --non-recursive.
> [Recursive listing snipped]
> If I compile the exactly the same code under MSVC++ 7.1 and invoke the
> executable it produces with the exactly the same script, the output is:
> Performing a scan without using recursion
> Will perform a non-recursive scan of directory c:\coding\cygwin\c++\.
> [Non-recursive listing snipped]
> What's going on here? Why doesn't strcmp() return 0 if compiled with g++
> with the input given above?

Apparently MSVCRT's startup code considers \r to be whitespace, and
Cygwin's doesn't.  Use Unix line endings, or put the script on a text
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw
Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]