3 This software is a copyrighted work licensed under the terms of the
4 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
8 /* Hack for Cygwin processes. If the Windows command line length gets slightly
9 bigger than this value, the stack position is suddenly moved up by 64K for
10 no apparent reason, which results in subsequent forks failing. Since Cygwin
11 processes get the full command line as argv array anyway, this only affects
12 the maximum command line length of Cygwin applications which nonsensically
13 have a WinMain instead of a main entry point or which use GetCommandLine. */
14 #define MAXCYGWINCMDLEN 30000
16 #define MAXWINCMDLEN 32767
17 #define LINE_BUF_CHUNK (MAX_PATH * 2)
26 av () : argv (NULL
), argc (0) {}
27 av (int ac_in
, const char * const *av_in
)
28 : calloced (0), win16_exe (false)
30 argv
= (char **) cmalloc (HEAP_1_ARGV
, (ac_in
+ 5) * sizeof (char *));
34 memcpy (argv
, av_in
, (argc
+ 1) * sizeof (char *));
37 void *operator new (size_t, void *p
) __attribute__ ((nothrow
)) {return p
;}
42 for (int i
= 0; i
< calloced
; i
++)
47 int unshift (const char *what
);
48 operator char **() {return argv
;}
49 void all_calloced () {calloced
= argc
;}
50 void replace0_maybe (const char *arg0
)
52 /* Note: Assumes that argv array has not yet been "unshifted" */
55 argv
[0] = cstrdup1 (arg0
);
61 for (int i
= calloced
; i
< argc
; i
++)
62 argv
[i
] = cstrdup1 (argv
[i
]);
65 int setup (const char *, path_conv
&, const char *, int, const char *const *,
75 linebuf () : ix (0), buf (NULL
), alloced (0) {}
76 ~linebuf () {if (buf
) free (buf
);}
77 void add (const char *, int);
78 void add (const char *what
) {add (what
, strlen (what
));}
79 void prepend (const char *, int);
81 bool fromargv(av
&, const char *, bool);;
82 operator size_t () const { return ix
+ 1; }
83 operator const char * () const { return buf
; }
87 /* Note that this malloc'ed buffer is not freed by the destructor.
88 It is up to the caller to do (or not do) that. */
89 wchar_t *wbuf
= (wchar_t *) malloc (sizeof (wchar_t) * n
);
92 wchar_t *wcs (wchar_t *wbuf
) { return wcs (wbuf
, ix
+ 1); }
93 wchar_t *wcs (wchar_t *wbuf
, size_t n
)
98 sys_mbstowcs (wbuf
, n
, buf
);