Initialize lpdwNeeded.
[wine/multimedia.git] / files / change.c
blob3dde14cdd0bdcb78358b703d1252a50f48a999c0
1 /*
2 * Win32 file change notification functions
4 * Copyright 1998 Ulrich Weigand
5 */
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <time.h>
12 #include "windows.h"
13 #include "winbase.h"
14 #include "winerror.h"
15 #include "process.h"
16 #include "thread.h"
17 #include "heap.h"
18 #include "server.h"
19 #include "debug.h"
21 static void CHANGE_Destroy( K32OBJ *obj );
23 const K32OBJ_OPS CHANGE_Ops =
25 CHANGE_Destroy /* destroy */
28 /* The change notification object */
29 typedef struct
31 K32OBJ header;
32 LPSTR lpPathName;
33 BOOL32 bWatchSubtree;
34 DWORD dwNotifyFilter;
35 BOOL32 notify;
36 } CHANGE_OBJECT;
38 /****************************************************************************
39 * CHANGE_Destroy
41 static void CHANGE_Destroy( K32OBJ *obj )
43 CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
44 assert( obj->type == K32OBJ_CHANGE );
46 if ( change->lpPathName )
48 HeapFree( SystemHeap, 0, change->lpPathName );
49 change->lpPathName = NULL;
52 obj->type = K32OBJ_UNKNOWN;
53 HeapFree( SystemHeap, 0, change );
56 /****************************************************************************
57 * FindFirstChangeNotification32A (KERNEL32.248)
59 HANDLE32 WINAPI FindFirstChangeNotification32A( LPCSTR lpPathName,
60 BOOL32 bWatchSubtree,
61 DWORD dwNotifyFilter )
63 CHANGE_OBJECT *change;
64 struct create_change_notification_request req;
65 struct create_change_notification_reply reply;
67 req.subtree = bWatchSubtree;
68 req.filter = dwNotifyFilter;
69 CLIENT_SendRequest( REQ_CREATE_CHANGE_NOTIFICATION, -1, 1, &req, sizeof(req) );
70 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
71 if (reply.handle == -1) return INVALID_HANDLE_VALUE32;
73 change = HeapAlloc( SystemHeap, 0, sizeof(CHANGE_OBJECT) );
74 if (!change)
76 CLIENT_CloseHandle( reply.handle );
77 return INVALID_HANDLE_VALUE32;
80 change->header.type = K32OBJ_CHANGE;
81 change->header.refcount = 1;
83 change->lpPathName = HEAP_strdupA( SystemHeap, 0, lpPathName );
84 change->bWatchSubtree = bWatchSubtree;
85 change->dwNotifyFilter = dwNotifyFilter;
86 change->notify = FALSE;
88 return HANDLE_Alloc( PROCESS_Current(), &change->header,
89 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE /*FIXME*/,
90 FALSE, reply.handle );
93 /****************************************************************************
94 * FindFirstChangeNotification32W (KERNEL32.249)
96 HANDLE32 WINAPI FindFirstChangeNotification32W( LPCWSTR lpPathName,
97 BOOL32 bWatchSubtree,
98 DWORD dwNotifyFilter)
100 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpPathName );
101 HANDLE32 ret = FindFirstChangeNotification32A( nameA, bWatchSubtree,
102 dwNotifyFilter );
103 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
104 return ret;
107 /****************************************************************************
108 * FindNextChangeNotification (KERNEL32.252)
110 BOOL32 WINAPI FindNextChangeNotification( HANDLE32 handle )
112 CHANGE_OBJECT *change;
114 SYSTEM_LOCK();
115 if (!(change = (CHANGE_OBJECT *)HANDLE_GetObjPtr( PROCESS_Current(),
116 handle, K32OBJ_CHANGE,
117 0 /*FIXME*/, NULL )) )
119 SYSTEM_UNLOCK();
120 return FALSE;
123 change->notify = FALSE;
124 K32OBJ_DecCount( &change->header );
125 SYSTEM_UNLOCK();
126 return TRUE;
129 /****************************************************************************
130 * FindCloseChangeNotification (KERNEL32.247)
132 BOOL32 WINAPI FindCloseChangeNotification( HANDLE32 handle)
134 return CloseHandle( handle );