2006-04-12 23:53:22 +08:00
|
|
|
/* winf.h
|
|
|
|
|
2015-02-11 21:15:59 +08:00
|
|
|
Copyright 2006, 2007, 2009, 2011, 2013, 2015 Red Hat, Inc.
|
2006-04-12 23:53:22 +08:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2013-07-20 01:28:34 +08:00
|
|
|
#pragma once
|
2006-04-13 09:37:00 +08:00
|
|
|
/* Hack for Cygwin processes. If the Windows command line length gets slightly
|
|
|
|
bigger than this value, the stack position is suddenly moved up by 64K for
|
|
|
|
no apparent reason, which results in subsequent forks failing. Since Cygwin
|
|
|
|
processes get the full command line as argv array anyway, this only affects
|
2006-05-29 23:51:18 +08:00
|
|
|
the maximum command line length of Cygwin applications which nonsensically
|
|
|
|
have a WinMain instead of a main entry point or which use GetCommandLine. */
|
|
|
|
#define MAXCYGWINCMDLEN 30000
|
2006-04-13 09:37:00 +08:00
|
|
|
|
2006-04-12 23:53:22 +08:00
|
|
|
#define MAXWINCMDLEN 32767
|
2007-12-05 23:10:20 +08:00
|
|
|
#define LINE_BUF_CHUNK (MAX_PATH * 2)
|
2006-04-12 23:53:22 +08:00
|
|
|
|
|
|
|
class av
|
|
|
|
{
|
|
|
|
char **argv;
|
|
|
|
int calloced;
|
|
|
|
public:
|
|
|
|
int argc;
|
|
|
|
bool win16_exe;
|
2007-02-23 20:01:52 +08:00
|
|
|
av (): argv (NULL) {}
|
|
|
|
av (int ac_in, const char * const *av_in) : calloced (0), argc (ac_in), win16_exe (false)
|
2006-04-12 23:53:22 +08:00
|
|
|
{
|
2007-11-27 05:30:49 +08:00
|
|
|
argv = (char **) cmalloc_abort (HEAP_1_ARGV, (argc + 5) * sizeof (char *));
|
2006-04-12 23:53:22 +08:00
|
|
|
memcpy (argv, av_in, (argc + 1) * sizeof (char *));
|
|
|
|
}
|
|
|
|
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
|
|
|
|
~av ()
|
|
|
|
{
|
|
|
|
if (argv)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < calloced; i++)
|
2013-06-20 00:00:43 +08:00
|
|
|
cfree (argv[i]);
|
2006-04-12 23:53:22 +08:00
|
|
|
cfree (argv);
|
|
|
|
}
|
|
|
|
}
|
2015-02-11 21:15:59 +08:00
|
|
|
int unshift (const char *what) __reg2;
|
2006-04-12 23:53:22 +08:00
|
|
|
operator char **() {return argv;}
|
|
|
|
void all_calloced () {calloced = argc;}
|
|
|
|
void replace0_maybe (const char *arg0)
|
|
|
|
{
|
|
|
|
/* Note: Assumes that argv array has not yet been "unshifted" */
|
|
|
|
if (!calloced)
|
|
|
|
{
|
|
|
|
argv[0] = cstrdup1 (arg0);
|
2013-06-20 00:00:43 +08:00
|
|
|
calloced = 1;
|
2006-04-12 23:53:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void dup_all ()
|
|
|
|
{
|
|
|
|
for (int i = calloced; i < argc; i++)
|
|
|
|
argv[i] = cstrdup1 (argv[i]);
|
2013-06-20 00:00:43 +08:00
|
|
|
calloced = argc;
|
2006-04-12 23:53:22 +08:00
|
|
|
}
|
2013-06-20 01:21:25 +08:00
|
|
|
int setup (const char *, path_conv&, const char *, int, const char *const *,
|
|
|
|
bool) __reg3;
|
2006-04-12 23:53:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class linebuf
|
|
|
|
{
|
|
|
|
size_t ix;
|
|
|
|
char *buf;
|
|
|
|
size_t alloced;
|
2013-07-20 01:28:34 +08:00
|
|
|
public:
|
2006-04-12 23:53:22 +08:00
|
|
|
linebuf () : ix (0), buf (NULL), alloced (0) {}
|
|
|
|
~linebuf () {if (buf) free (buf);}
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg3 add (const char *, int);
|
2006-04-12 23:53:22 +08:00
|
|
|
void add (const char *what) {add (what, strlen (what));}
|
2009-08-02 03:52:46 +08:00
|
|
|
void prepend (const char *, int);
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg2 finish (bool);
|
|
|
|
bool __reg3 fromargv(av&, const char *, bool);;
|
2013-07-20 01:28:34 +08:00
|
|
|
operator size_t () const { return ix + 1; }
|
|
|
|
operator const char * () const { return buf; }
|
|
|
|
operator wchar_t * ()
|
|
|
|
{
|
|
|
|
size_t n = ix + 1;
|
|
|
|
/* Note that this malloc'ed buffer is not freed by the destructor.
|
|
|
|
It is up to the caller to do (or not do) that. */
|
|
|
|
wchar_t *wbuf = (wchar_t *) malloc (sizeof (wchar_t) * n);
|
|
|
|
return wcs (wbuf, n);
|
|
|
|
}
|
2013-07-20 06:44:02 +08:00
|
|
|
wchar_t *wcs (wchar_t *wbuf) { return wcs (wbuf, ix + 1); }
|
2013-07-20 01:28:34 +08:00
|
|
|
wchar_t *wcs (wchar_t *wbuf, size_t n)
|
|
|
|
{
|
|
|
|
if (n == 1)
|
|
|
|
wbuf[0] = L'\0';
|
|
|
|
else
|
|
|
|
sys_mbstowcs (wbuf, n, buf);
|
|
|
|
return wbuf;
|
|
|
|
}
|
2006-04-12 23:53:22 +08:00
|
|
|
};
|