Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-05-09 05:56:34 +0400
committerChristopher Faylor <me@cgf.cx>2005-05-09 05:56:34 +0400
commitf991d0e53ebed74e93a7d0ff4c878ed0f37f2742 (patch)
tree5d837ea00e4eeb29f322bf46726d97bf0949dbeb /winsup/utils
parent26c07f704b8f95681afe552fe21cd186574b4044 (diff)
* cygcheck.cc (nuke): New function.
(load_cygwin): New function. (main): Use load_cygwin to load argv/envp from cygwin environment, if appropriate.
Diffstat (limited to 'winsup/utils')
-rw-r--r--winsup/utils/ChangeLog7
-rw-r--r--winsup/utils/cygcheck.cc40
2 files changed, 47 insertions, 0 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 9438a5586..27477891e 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,5 +1,12 @@
2005-05-08 Christopher Faylor <cgf@timesys.com>
+ * cygcheck.cc (nuke): New function.
+ (load_cygwin): New function.
+ (main): Use load_cygwin to load argv/envp from cygwin environment, if
+ appropriate.
+
+2005-05-08 Christopher Faylor <cgf@timesys.com>
+
* strace.cc (attach_process): Don't call load_cygwin(). Assume that
it's already happened.
(dotoggle): Ditto.
diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc
index c8bcff600..dd815b9ed 100644
--- a/winsup/utils/cygcheck.cc
+++ b/winsup/utils/cygcheck.cc
@@ -8,6 +8,7 @@
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
+#define cygwin_internal cygwin_internal_dontuse
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -19,6 +20,7 @@
#include <getopt.h>
#include "cygwin/include/sys/cygwin.h"
#include "cygwin/include/mntent.h"
+#undef cygwin_internal
#define alloca __builtin_alloca
@@ -1427,10 +1429,48 @@ Compiled on %s\n\
", len, v, __DATE__);
}
+void
+nuke (char *ev)
+{
+ int n = 1 + strchr (*_environ, '=') - ev;
+ char *s = (char *) alloca (n);
+ memcpy (s, ev, n);
+ s[n] = '\0';
+ putenv (s);
+}
+
+DWORD (*cygwin_internal) (int, ...);
+
+static void
+load_cygwin (int& argc, char **&argv)
+{
+ HMODULE h;
+
+ if (!(h = LoadLibrary ("cygwin1.dll")))
+ return;
+ if (!(cygwin_internal = (DWORD (*) (int, ...)) GetProcAddress (h, "cygwin_internal")))
+ return;
+
+ char **av = (char **) cygwin_internal (CW_ARGV);
+ if (av)
+ for (argc = 0, argv = av; *av; av++)
+ argc++;
+
+ char **envp = (char **) cygwin_internal (CW_ENVP);
+ if (envp)
+ {
+ while (*_environ)
+ nuke (*_environ);
+ for (char **ev = envp; *ev; ev++)
+ putenv (*ev);
+ }
+}
+
int
main (int argc, char **argv)
{
int i;
+ load_cygwin (argc, argv);
(void) putenv("POSIXLY_CORRECT=1");
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)