Fix existing string functions, implement a bunch of new ones.
[wine/hacks.git] / scheduler / handle.c
blobe24f0e2cdab54f4670177ab73c34eab8d6308fbd
1 /*
2 * Win32 process handles
4 * Copyright 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <assert.h>
24 #include <stdio.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include "winbase.h"
29 #include "wine/server.h"
30 #include "winerror.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(win32);
35 /*********************************************************************
36 * CloseW32Handle (KERNEL.474)
37 * CloseHandle (KERNEL32.@)
39 BOOL WINAPI CloseHandle( HANDLE handle )
41 NTSTATUS status;
43 /* stdio handles need special treatment */
44 if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
45 (handle == (HANDLE)STD_OUTPUT_HANDLE) ||
46 (handle == (HANDLE)STD_ERROR_HANDLE))
47 handle = GetStdHandle( (DWORD)handle );
49 status = NtClose( handle );
50 if (status) SetLastError( RtlNtStatusToDosError(status) );
51 return !status;
55 /*********************************************************************
56 * GetHandleInformation (KERNEL32.@)
58 BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
60 BOOL ret;
61 SERVER_START_REQ( set_handle_info )
63 req->handle = handle;
64 req->flags = 0;
65 req->mask = 0;
66 req->fd = -1;
67 ret = !wine_server_call_err( req );
68 if (ret && flags) *flags = reply->old_flags;
70 SERVER_END_REQ;
71 return ret;
75 /*********************************************************************
76 * SetHandleInformation (KERNEL32.@)
78 BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
80 BOOL ret;
81 SERVER_START_REQ( set_handle_info )
83 req->handle = handle;
84 req->flags = flags;
85 req->mask = mask;
86 req->fd = -1;
87 ret = !wine_server_call_err( req );
89 SERVER_END_REQ;
90 return ret;
94 /*********************************************************************
95 * DuplicateHandle (KERNEL32.@)
97 BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
98 HANDLE dest_process, HANDLE *dest,
99 DWORD access, BOOL inherit, DWORD options )
101 BOOL ret;
102 SERVER_START_REQ( dup_handle )
104 req->src_process = source_process;
105 req->src_handle = source;
106 req->dst_process = dest_process;
107 req->access = access;
108 req->inherit = inherit;
109 req->options = options;
111 ret = !wine_server_call_err( req );
112 if (ret)
114 if (dest) *dest = reply->handle;
115 if (reply->fd != -1) close( reply->fd );
118 SERVER_END_REQ;
119 return ret;
123 /***********************************************************************
124 * ConvertToGlobalHandle (KERNEL.476)
125 * ConvertToGlobalHandle (KERNEL32.@)
127 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
129 HANDLE ret = INVALID_HANDLE_VALUE;
130 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
131 DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
132 return ret;
135 /***********************************************************************
136 * SetHandleContext (KERNEL32.@)
138 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context) {
139 FIXME("(%d,%ld), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
140 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
141 return FALSE;
144 /***********************************************************************
145 * GetHandleContext (KERNEL32.@)
147 DWORD WINAPI GetHandleContext(HANDLE hnd) {
148 FIXME("(%d), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
149 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
150 return 0;
153 /***********************************************************************
154 * CreateSocketHandle (KERNEL32.@)
156 HANDLE WINAPI CreateSocketHandle(void) {
157 FIXME("(), stub. In case this got called by WSOCK32/WS2_32: the external WINSOCK DLLs won't work with WINE, don't use them.\n");
158 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
159 return INVALID_HANDLE_VALUE;