newlib/winsup/cygwin/winf.h
Christopher Faylor fafbf75509 * cygheap_malloc.h: New file.
* cygheap.h: Remove stuff now included in cygheap_malloc.h and include that
file.  Make cygheap_init a standard c++ function.  Remove unneeded child_info
declaration.
* path.h: Include cygheap_malloc.h.  Remove extra cstrdup declaration.
(path_conv): Reorganize to group variables together.
(path_conv::path): Make const char *.
(path_conv::known_suffix): Ditto.
(path_conv::normalized_path): Ditto.
(path_conv::path_conv): Reorganize initializers to reflect new element
ordering.
(path_conv::get_win32): Change return value to const char *.
(path_conv::set_path): Move back here from spawn.cc.
(parh_conv::modifiable_path): New function.
* path.cc (path_conv::add_ext_from_sym): Accommodate const'ness of
known_suffixes.
(path_conv::set_normalized_path): Ditto for normalized_path.
(path_conv::check): Use modifiable_path whereever we need to modify the path
element.  Use set_path to set the path.
(path_conv::~path_conv): Accommodate new const'ness.
* spawn.cc (perhaps_suffix): Declare ext as const since that's what is being
returned.
(path_conv::set_path): Move back to path.h.
* winf.f (linebuf): Perform minor cleanup.
(linebuf::fromargv): Change second parameter to const.
* winf.cc (linebuf::fromargv): Ditto.
2009-08-01 19:52:46 +00:00

90 lines
2.4 KiB
C++

/* winf.h
Copyright 2006, 2007 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _WINF_H
#define _WINF_H
/* 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
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
#define MAXWINCMDLEN 32767
#define LINE_BUF_CHUNK (MAX_PATH * 2)
class av
{
char **argv;
int calloced;
public:
int argc;
bool win16_exe;
av (): argv (NULL) {}
av (int ac_in, const char * const *av_in) : calloced (0), argc (ac_in), win16_exe (false)
{
argv = (char **) cmalloc_abort (HEAP_1_ARGV, (argc + 5) * sizeof (char *));
memcpy (argv, av_in, (argc + 1) * sizeof (char *));
}
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
void set (int ac_in, const char * const *av_in) {new (this) av (ac_in, av_in);}
~av ()
{
if (argv)
{
for (int i = 0; i < calloced; i++)
if (argv[i])
cfree (argv[i]);
cfree (argv);
}
}
int unshift (const char *what, int conv = 0);
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);
calloced = true;
}
}
void dup_maybe (int i)
{
if (i >= calloced)
argv[i] = cstrdup1 (argv[i]);
}
void dup_all ()
{
for (int i = calloced; i < argc; i++)
argv[i] = cstrdup1 (argv[i]);
}
int fixup (const char *, path_conv&, const char *);
};
class linebuf
{
public:
size_t ix;
char *buf;
size_t alloced;
linebuf () : ix (0), buf (NULL), alloced (0) {}
~linebuf () {if (buf) free (buf);}
void add (const char *, int) __attribute__ ((regparm (3)));
void add (const char *what) {add (what, strlen (what));}
void prepend (const char *, int);
void finish (bool) __attribute__ ((regparm (2)));
bool fromargv(av&, const char *, bool) __attribute__ ((regparm (3)));;
operator char *() {return buf;}
};
#endif /*_WINF_H*/