dmloader: complete rewrite and full implementation.
[wine] / dlls / kernel / change.c
1 /*
2  * Win32 file change notification functions
3  *
4  * Copyright 1998 Ulrich Weigand
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "ntstatus.h"
31 #include "wine/windef16.h"
32 #include "wine/server.h"
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(file);
36
37 /****************************************************************************
38  *              FindFirstChangeNotificationA (KERNEL32.@)
39  */
40 HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
41                                             DWORD dwNotifyFilter )
42 {
43     UNICODE_STRING pathW;
44     HANDLE ret = INVALID_HANDLE_VALUE;
45
46     if (RtlCreateUnicodeStringFromAsciiz( &pathW, lpPathName ))
47     {
48         ret = FindFirstChangeNotificationW( pathW.Buffer, bWatchSubtree, dwNotifyFilter );
49         RtlFreeUnicodeString( &pathW );
50     }
51     else SetLastError( ERROR_NOT_ENOUGH_MEMORY );
52     return ret;
53 }
54
55 /****************************************************************************
56  *              FindFirstChangeNotificationW (KERNEL32.@)
57  */
58 HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree,
59                                             DWORD dwNotifyFilter)
60 {
61     UNICODE_STRING nt_name;
62     OBJECT_ATTRIBUTES attr;
63     IO_STATUS_BLOCK io;
64     NTSTATUS status;
65     HANDLE file, ret = INVALID_HANDLE_VALUE;
66
67     TRACE( "%s %d %lx\n", debugstr_w(lpPathName), bWatchSubtree, dwNotifyFilter );
68
69     if (!RtlDosPathNameToNtPathName_U( lpPathName, &nt_name, NULL, NULL ))
70     {
71         SetLastError( ERROR_PATH_NOT_FOUND );
72         return INVALID_HANDLE_VALUE;
73     }
74
75     attr.Length = sizeof(attr);
76     attr.RootDirectory = 0;
77     attr.Attributes = OBJ_CASE_INSENSITIVE;
78     attr.ObjectName = &nt_name;
79     attr.SecurityDescriptor = NULL;
80     attr.SecurityQualityOfService = NULL;
81
82     status = NtOpenFile( &file, 0, &attr, &io, 0,
83                          FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
84     RtlFreeUnicodeString( &nt_name );
85
86     if (status != STATUS_SUCCESS)
87     {
88         SetLastError( RtlNtStatusToDosError(status) );
89         return INVALID_HANDLE_VALUE;
90     }
91
92     SERVER_START_REQ( create_change_notification )
93     {
94         req->handle  = file;
95         req->subtree = bWatchSubtree;
96         req->filter  = dwNotifyFilter;
97         if (!wine_server_call_err( req )) ret = reply->handle;
98     }
99     SERVER_END_REQ;
100     CloseHandle( file );
101     return ret;
102 }
103
104 /****************************************************************************
105  *              FindNextChangeNotification (KERNEL32.@)
106  */
107 BOOL WINAPI FindNextChangeNotification( HANDLE handle )
108 {
109     BOOL ret;
110
111     TRACE("%p\n",handle);
112
113     SERVER_START_REQ( next_change_notification )
114     {
115         req->handle = handle;
116         ret = !wine_server_call_err( req );
117     }
118     SERVER_END_REQ;
119     return ret;
120 }
121
122 /****************************************************************************
123  *              FindCloseChangeNotification (KERNEL32.@)
124  */
125 BOOL WINAPI FindCloseChangeNotification( HANDLE handle )
126 {
127     return CloseHandle( handle );
128 }
129
130 /***********************************************************************
131 *       FileCDR (KERNEL.130)
132 */
133 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
134 {
135     FIXME("(0x%8x): stub\n", (int) x);
136     return (FARPROC16)TRUE;
137 }