Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / local_includes / winf.h
blobb58693441095815830945692f3c071975d8e89f8
1 /* winf.h
3 This software is a copyrighted work licensed under the terms of the
4 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
5 details. */
7 #pragma once
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)
19 class av
21 char **argv;
22 int calloced;
23 public:
24 int argc;
25 bool win16_exe;
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 *));
31 if (argv)
33 argc = ac_in;
34 memcpy (argv, av_in, (argc + 1) * sizeof (char *));
37 void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
38 ~av ()
40 if (argv)
42 for (int i = 0; i < calloced; i++)
43 cfree (argv[i]);
44 cfree (argv);
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" */
53 if (!calloced)
55 argv[0] = cstrdup1 (arg0);
56 calloced = 1;
59 void dup_all ()
61 for (int i = calloced; i < argc; i++)
62 argv[i] = cstrdup1 (argv[i]);
63 calloced = argc;
65 int setup (const char *, path_conv&, const char *, int, const char *const *,
66 bool);
69 class linebuf
71 size_t ix;
72 char *buf;
73 size_t alloced;
74 public:
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);
80 void finish (bool);
81 bool fromargv(av&, const char *, bool);;
82 operator size_t () const { return ix + 1; }
83 operator const char * () const { return buf; }
84 operator wchar_t * ()
86 size_t n = ix + 1;
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);
90 return wcs (wbuf, n);
92 wchar_t *wcs (wchar_t *wbuf) { return wcs (wbuf, ix + 1); }
93 wchar_t *wcs (wchar_t *wbuf, size_t n)
95 if (n == 1)
96 wbuf[0] = L'\0';
97 else
98 sys_mbstowcs (wbuf, n, buf);
99 return wbuf;