Implemented file change notifications, based on a patch by Mike
[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 <stdlib.h>
24 #include <string.h>
25
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wine/server.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(file);
32
33 /****************************************************************************
34  *              FindFirstChangeNotificationA (KERNEL32.@)
35  */
36 HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
37                                             DWORD dwNotifyFilter )
38 {
39     HANDLE file, ret = INVALID_HANDLE_VALUE;
40
41     TRACE( "%s %d %lx\n", debugstr_a(lpPathName), bWatchSubtree, dwNotifyFilter );
42
43     if ((file = CreateFileA( lpPathName, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
44                              OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 )) == INVALID_HANDLE_VALUE)
45         return INVALID_HANDLE_VALUE;
46
47     SERVER_START_REQ( create_change_notification )
48     {
49         req->handle  = file;
50         req->subtree = bWatchSubtree;
51         req->filter  = dwNotifyFilter;
52         if (!wine_server_call_err( req )) ret = reply->handle;
53     }
54     SERVER_END_REQ;
55     CloseHandle( file );
56     return ret;
57 }
58
59 /****************************************************************************
60  *              FindFirstChangeNotificationW (KERNEL32.@)
61  */
62 HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree,
63                                             DWORD dwNotifyFilter)
64 {
65     HANDLE file, ret = INVALID_HANDLE_VALUE;
66
67     TRACE( "%s %d %lx\n", debugstr_w(lpPathName), bWatchSubtree, dwNotifyFilter );
68
69     if ((file = CreateFileW( lpPathName, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
70                              OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 )) == INVALID_HANDLE_VALUE)
71         return INVALID_HANDLE_VALUE;
72
73     SERVER_START_REQ( create_change_notification )
74     {
75         req->handle  = file;
76         req->subtree = bWatchSubtree;
77         req->filter  = dwNotifyFilter;
78         if (!wine_server_call_err( req )) ret = reply->handle;
79     }
80     SERVER_END_REQ;
81     CloseHandle( file );
82     return ret;
83 }
84
85 /****************************************************************************
86  *              FindNextChangeNotification (KERNEL32.@)
87  */
88 BOOL WINAPI FindNextChangeNotification( HANDLE handle )
89 {
90     BOOL ret;
91
92     TRACE("%p\n",handle);
93
94     SERVER_START_REQ( next_change_notification )
95     {
96         req->handle = handle;
97         ret = !wine_server_call_err( req );
98     }
99     SERVER_END_REQ;
100     return ret;
101 }
102
103 /****************************************************************************
104  *              FindCloseChangeNotification (KERNEL32.@)
105  */
106 BOOL WINAPI FindCloseChangeNotification( HANDLE handle )
107 {
108     return CloseHandle( handle );
109 }