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=wPlkd0S
	FDVN3w8Y3AvZgvQo4wCtgLcrCX7NczFEWdjWGAFfr0jKFDceQcO13igTlVsQNGo8
	173UDNejfucvlTac9kVp6pTtS10vMmVVKRMoV+t1qB8vAa1cAK+DZcAljg8ScmIW
	bbZoJD6o//lmLM2Cg4AjRwcy3Y+KJSisHwa4=
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=Gw/vxmS5vZtaA
	SLDxHzuj4Kzg2w=; b=ZK8rlnQVqaaseKj81/EVb9/crEethsDkwkcnJ7tcDLH3L
	2GTbqMrhLoS6+eOai+/0Kof6WsofP6aT4EVnkS4pQpPaQXtz0eHBOFOHFQxEEPVN
	GAdkCLomqZ96Vx1sfOgxCIGGmb0/a2zmRfSF3gDDL8gQg0ldf5r+hf5P9wkDhc=
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.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-oa0-f43.google.com
X-Received: by 10.60.70.200 with SMTP id o8mr27300377oeu.55.1401196823419; Tue, 27 May 2014 06:20:23 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw@mail.gmail.com>
References: <CANMjiJqz6uJ7pp=iS5FK_ZnS9nxCT1fY+EndcgzPan7sv2pXJA@mail.gmail.com> <20140526200857.GA3903@ednor.casa.cgf.cx> <lm08n5$tgp$1@ger.gmane.org> <20140526212219.GA4754@ednor.casa.cgf.cx> <CANMjiJpDU-aVxg1X8G_Lk8pKLEmXbs24+ieD=w3f8ZmQ2jdjTw@mail.gmail.com>
From: Abhijit Bhattacharjee <itabhijitb@gmail.com>
Date: Tue, 27 May 2014 18:49:43 +0530
Message-ID: <CANMjiJqkm1pD5zuKWc_aRw8h9mzfdpwSkk6u6ybLmgHKGEd0PQ@mail.gmail.com>
Subject: Re: Bash silently truncates the Command Line when called programatically via CreateProcess as MAXPATHLEN was reduced to 8192 from 16384
To: cygwin@cygwin.com
Content-Type: text/plain; charset=UTF-8
X-IsSubscribed: yes

Yes, MSVS is Microsoft Visual Studio.

and I am using the make for Windows
(http://gnuwin32.sourceforge.net/packages/make.htm).

Please note, when I am saying the path is getting truncated, its the
bash that is truncating it. Also, its immaterial how and what is
getting called. With the latest Cygwin, any program that is compiled
and linked with the CRT would exhibit this behavior. The truncation
issue in the CRT is best demonstrated by the following Code couplets

Caller.cpp
--------------
#include <iostream>
#include <windows.h>
#include <string.h>
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
int main(int argc, char *argv[]) {
    if (argc <= 1) return -1;
    char arg[10000] = {0};
    strncpy(arg, argv[argc-1], _countof(arg));
    strncat(arg," ", _countof(arg));
    memset(arg + strlen(arg), 'X', _countof(arg) - strlen(arg) - 2);
    strncat(arg, "\"", _countof(arg));
    STARTUPINFO startInfo;
    PROCESS_INFORMATION procInfo;
    memset( &startInfo, 0, sizeof(startInfo) );
    memset( &procInfo, 0, sizeof(procInfo) );
    if (CreateProcess(NULL,
        arg,
        NULL,
        0,
        TRUE,
        0,
        NULL,
        NULL,
        &startInfo,
        &procInfo) == FALSE) {
            std::cout<<"Error Code "<<GetLastError()<<std::endl;
    } else {
        WaitForSingleObject(procInfo.hProcess, INFINITE );
        CloseHandle( procInfo.hProcess );
        CloseHandle( procInfo.hThread );
        std::cout<<"Send Length "<<strlen(arg)<<std::endl;
    }
    return 0;
};

Callee.cpp
-------------

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <windows.h>
int main (int argc, char **argv) {
    printf("%s\n",argv[argc-1]);
    printf("%d\n",argc);
    printf("Received Length %d\n",strlen(argv[argc-1]));
    return 0;

}


Compile and Run The Programs as
-----------------------------------------

$g++ -g -o Caller.exe Caller.cpp
$g++ -g -o Callee.exe Callee.cpp
$./Caller.exe Callee.exe




Also Note, if you would like to review the code that is responsible
for the truncation, I would suggest you to refer the function

Source: winsup\cygwin\glob.cc
int glob(const char *__restrict pattern, int flags, int
(*errfunc)(const char *, int), glob_t *__restrict pglob)

and notice pathbuf is defined as

Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;

where

#undef MAXPATHLEN
#define MAXPATHLEN 8192

and to complete here is the call stack

glob(const char *__restrict pattern, int flags, int (*errfunc)(const
char *, int), glob_t *__restrict pglob)
globify (char *word, char **&argv, int &argc, int &argvlen)  - Line
265 of winsup\cygwin\dcrt0.cc
build_argv (char *cmd, char **&argv, int &argc, int winshell) - Line
353 of winsup\cygwin\dcrt0.cc
dll_crt0_1 (void *) - Line 953 of winsup\cygwin\dcrt0.cc
_dll_crt0 () - Line 1098 of winsup\cygwin\dcrt0.cc
dll_crt0 - Line 1110 of winsup\cygwin\dcrt0.cc

Rgrds,
Abhijit

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

