- Added a global label for elf-dll linking and a long with the resource
[wine.git] / files / change.c
blob5b99ca5eb8ef3ef8b7f5c437b6d37657d20884cf
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 "debug.h"
20 static BOOL32 CHANGE_Signaled( K32OBJ *obj, DWORD thread_id );
21 static BOOL32 CHANGE_Satisfied( K32OBJ *obj, DWORD thread_id );
22 static void CHANGE_AddWait( K32OBJ *obj, DWORD thread_id );
23 static void CHANGE_RemoveWait( K32OBJ *obj, DWORD thread_id );
24 static void CHANGE_Destroy( K32OBJ *obj );
26 const K32OBJ_OPS CHANGE_Ops =
28 CHANGE_Signaled, /* signaled */
29 CHANGE_Satisfied, /* satisfied */
30 CHANGE_AddWait, /* add_wait */
31 CHANGE_RemoveWait, /* remove_wait */
32 NULL, /* read */
33 NULL, /* write */
34 CHANGE_Destroy /* destroy */
37 /* The change notification object */
38 typedef struct
40 K32OBJ header;
42 LPSTR lpPathName;
43 BOOL32 bWatchSubtree;
44 DWORD dwNotifyFilter;
46 THREAD_QUEUE wait_queue;
47 BOOL32 notify;
49 } CHANGE_OBJECT;
51 /***********************************************************************
52 * CHANGE_Signaled
54 static BOOL32 CHANGE_Signaled( K32OBJ *obj, DWORD thread_id )
56 CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
57 assert( obj->type == K32OBJ_CHANGE );
58 return change->notify;
61 /***********************************************************************
62 * CHANGE_Satisfied
64 * Wait on this object has been satisfied.
66 static BOOL32 CHANGE_Satisfied( K32OBJ *obj, DWORD thread_id )
68 assert( obj->type == K32OBJ_CHANGE );
69 return FALSE; /* Not abandoned */
72 /***********************************************************************
73 * CHANGE_AddWait
75 * Add thread to object wait queue.
77 static void CHANGE_AddWait( K32OBJ *obj, DWORD thread_id )
79 CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
80 assert( obj->type == K32OBJ_CHANGE );
81 THREAD_AddQueue( &change->wait_queue, THREAD_ID_TO_THDB(thread_id) );
84 /***********************************************************************
85 * CHANGE_RemoveWait
87 * Remove thread from object wait queue.
89 static void CHANGE_RemoveWait( K32OBJ *obj, DWORD thread_id )
91 CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
92 assert( obj->type == K32OBJ_CHANGE );
93 THREAD_RemoveQueue( &change->wait_queue, THREAD_ID_TO_THDB(thread_id) );
96 /****************************************************************************
97 * CHANGE_Destroy
99 static void CHANGE_Destroy( K32OBJ *obj )
101 CHANGE_OBJECT *change = (CHANGE_OBJECT *)obj;
102 assert( obj->type == K32OBJ_CHANGE );
104 if ( change->lpPathName )
106 HeapFree( SystemHeap, 0, change->lpPathName );
107 change->lpPathName = NULL;
110 obj->type = K32OBJ_UNKNOWN;
111 HeapFree( SystemHeap, 0, change );
114 /****************************************************************************
115 * FindFirstChangeNotification32A (KERNEL32.248)
117 HANDLE32 WINAPI FindFirstChangeNotification32A( LPCSTR lpPathName,
118 BOOL32 bWatchSubtree,
119 DWORD dwNotifyFilter )
121 HANDLE32 handle;
122 CHANGE_OBJECT *change;
124 change = HeapAlloc( SystemHeap, 0, sizeof(CHANGE_OBJECT) );
125 if (!change) return INVALID_HANDLE_VALUE32;
127 change->header.type = K32OBJ_CHANGE;
128 change->header.refcount = 1;
130 change->lpPathName = HEAP_strdupA( SystemHeap, 0, lpPathName );
131 change->bWatchSubtree = bWatchSubtree;
132 change->dwNotifyFilter = dwNotifyFilter;
134 change->wait_queue = NULL;
135 change->notify = FALSE;
137 handle = HANDLE_Alloc( PROCESS_Current(), &change->header,
138 FILE_ALL_ACCESS /*FIXME*/, TRUE, -1 );
139 /* If the allocation failed, the object is already destroyed */
140 if (handle == INVALID_HANDLE_VALUE32) change = NULL;
141 return handle;
144 /****************************************************************************
145 * FindFirstChangeNotification32W (KERNEL32.249)
147 HANDLE32 WINAPI FindFirstChangeNotification32W( LPCWSTR lpPathName,
148 BOOL32 bWatchSubtree,
149 DWORD dwNotifyFilter)
151 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpPathName );
152 HANDLE32 ret = FindFirstChangeNotification32A( nameA, bWatchSubtree,
153 dwNotifyFilter );
154 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
155 return ret;
158 /****************************************************************************
159 * FindNextChangeNotification (KERNEL32.252)
161 BOOL32 WINAPI FindNextChangeNotification( HANDLE32 handle )
163 CHANGE_OBJECT *change;
165 SYSTEM_LOCK();
166 if (!(change = (CHANGE_OBJECT *)HANDLE_GetObjPtr( PROCESS_Current(),
167 handle, K32OBJ_CHANGE,
168 0 /*FIXME*/, NULL )) )
170 SYSTEM_UNLOCK();
171 return FALSE;
174 change->notify = FALSE;
175 K32OBJ_DecCount( &change->header );
176 SYSTEM_UNLOCK();
177 return TRUE;
180 /****************************************************************************
181 * FindCloseChangeNotification (KERNEL32.247)
183 BOOL32 WINAPI FindCloseChangeNotification( HANDLE32 handle)
185 return CloseHandle( handle );