Release 951124
[wine] / win32 / init.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  */
6
7 #include <string.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include "windows.h"
11 #include "winerror.h"
12 #include "kernel32.h"
13 #include "handle32.h"
14 #include "stddebug.h"
15 #include "debug.h"
16   
17 /* The global error value
18  */
19 int WIN32_LastError;
20
21 /* Standard system handles for stdin, stdout, and stderr.
22  */
23 FILE_OBJECT *hstdin, *hstdout, *hstderr;
24
25 static int CreateStdHandles(void);
26
27 /*********************************************************************
28  *              CloseHandle             (KERNEL32.23)
29  */
30 BOOL CloseHandle(HANDLE32 handle)
31 {
32     int rc;
33
34     if(ValidateKernelObject(handle) != 0)
35     {
36         SetLastError(ERROR_INVALID_HANDLE);
37         return 0;
38     }
39
40     switch(handle->magic)
41     {
42         case KERNEL_OBJECT_UNUSED:
43             SetLastError(ERROR_INVALID_HANDLE);
44             return 0;
45
46         case KERNEL_OBJECT_FILE:
47             rc = CloseFileHandle((FILE_OBJECT *)handle);
48             break;
49
50         default:
51             printf("CloseHandle: type %ld not implemented yet.\n",
52                    handle->magic);
53             break;
54     }
55
56     ReleaseKernelObject(handle);
57     return 0;
58 }
59
60 /***********************************************************************
61  *              GetModuleFileNameA      (KERNEL32.235)
62  */
63 DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
64 {
65     strcpy(lpFilename, "c:\\dummy");
66     return 8;
67 }
68
69 /***********************************************************************
70  *              GetModuleHandle         (KERNEL32.237)
71  */
72 HMODULE WIN32_GetModuleHandle(char *module)
73 {
74     if(module == NULL)
75         return (HMODULE)0;
76     else
77         return GetModuleHandle(module);
78 }
79
80 /***********************************************************************
81  *              GetStartupInfoA         (KERNEL32.273)
82  */
83 VOID GetStartupInfoA(LPSTARTUPINFO lpStartupInfo)
84 {
85     lpStartupInfo->cb = sizeof(STARTUPINFO);
86     lpStartupInfo->lpReserved = NULL;
87     lpStartupInfo->lpDesktop = "Desktop";
88     lpStartupInfo->lpTitle = "Title";
89
90     lpStartupInfo->lpReserved2 = NULL; /* must be NULL for VC runtime */
91     lpStartupInfo->hStdInput  = (HANDLE)0;
92     lpStartupInfo->hStdOutput = (HANDLE)1;
93     lpStartupInfo->hStdError  = (HANDLE)2;
94 }
95
96 /* Initialize whatever internal data structures we need.
97  *
98  * Returns 1 on success, 0 on failure.
99  */
100 int KERN32_Init(void)
101 {
102     /* Create the standard system handles
103      */
104     if(CreateStdHandles() != 0)
105         return 0;
106
107     return 1;
108 }
109
110 /* CreateStdHandles creates the standard input, output, and error handles.
111  * These handles aren't likely to be used since they're generally used for
112  * console output, but startup code still likes to mess with them.  They're
113  * also useful for debugging since apps and runtime libraries might write
114  * errors to stderr.
115  *
116  * Returns 0 on success, nonzero on failure.
117  */
118 static int CreateStdHandles(void)
119 {
120     /* Create the standard input handle.
121      */
122     hstdin = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
123     if(hstdin == NULL)
124         return 1;
125     hstdin->common.magic = KERNEL_OBJECT_FILE;
126     hstdin->fd = 0;
127     hstdin->type = FILE_TYPE_CHAR;
128     hstdin->misc_flags = 0;
129
130     /* Create the standard output handle
131      */
132     hstdout = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
133     if(hstdout == NULL)
134         return 1;
135     hstdout->common.magic = KERNEL_OBJECT_FILE;
136     hstdout->fd = 1;
137     hstdout->type = FILE_TYPE_CHAR;
138     hstdout->misc_flags = 0;
139
140     /* Create the standard error handle
141      */
142     hstderr = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
143     if(hstderr == NULL)
144         return 1;
145     hstderr->common.magic = KERNEL_OBJECT_FILE;
146     hstderr->fd = 2;
147     hstderr->type = FILE_TYPE_CHAR;
148     hstderr->misc_flags = 0;
149
150     return 0;
151 }