Release 950727
[wine] / loader / selector.c
1 /*
2  * Selector manipulation functions
3  *
4  * Copyright 1993 Robert J. Amstadt
5  * Copyright 1995 Alexandre Julliard
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12
13 #ifndef WINELIB
14
15 #include "windows.h"
16 #include "global.h"
17 #include "module.h"
18 #include "stddebug.h"
19 /* #define DEBUG_SELECTORS */
20 #include "debug.h"
21
22
23 #define MAX_ENV_SIZE 16384  /* Max. environment size (ought to be dynamic) */
24
25 static HANDLE EnvironmentHandle = 0;
26
27
28 extern char WindowsPath[256];
29
30 extern char **environ;
31
32
33
34 WNDPROC GetWndProcEntry16( char *name )
35 {
36     WORD ordinal;
37     static HMODULE hModule = 0;
38
39     if (!hModule) hModule = GetModuleHandle( "WINPROCS" );
40     ordinal = MODULE_GetOrdinal( hModule, name );
41     return MODULE_GetEntryPoint( hModule, ordinal );
42 }
43
44
45 /***********************************************************************
46  *           GetDOSEnvironment   (KERNEL.131)
47  */
48 SEGPTR GetDOSEnvironment(void)
49 {
50     return WIN16_GlobalLock( EnvironmentHandle );
51 }
52
53
54 /**********************************************************************
55  *           CreateEnvironment
56  */
57 static HANDLE CreateEnvironment(void)
58 {
59     HANDLE handle;
60     char **e;
61     char *p;
62
63     handle = GlobalAlloc( GMEM_MOVEABLE, MAX_ENV_SIZE );
64     if (!handle) return 0;
65     p = (char *) GlobalLock( handle );
66
67     /*
68      * Fill environment with Windows path, the Unix environment,
69      * and program name.
70      */
71     strcpy(p, "PATH=");
72     strcat(p, WindowsPath);
73     p += strlen(p) + 1;
74
75     for (e = environ; *e; e++)
76     {
77         if (strncasecmp(*e, "path", 4))
78         {
79             strcpy(p, *e);
80             p += strlen(p) + 1;
81         }
82     }
83
84     *p++ = '\0';
85
86     /*
87      * Display environment
88      */
89     p = (char *) GlobalLock( handle );
90     dprintf_selectors(stddeb, "Environment at %p\n", p);
91     for (; *p; p += strlen(p) + 1) dprintf_selectors(stddeb, "    %s\n", p);
92
93     return handle;
94 }
95
96
97
98 /**********************************************************************
99  *                                      CreateSelectors
100  */
101 void CreateSelectors(void)
102 {
103     if(!EnvironmentHandle) EnvironmentHandle = CreateEnvironment();
104 }
105
106
107 #endif /* ifndef WINELIB */