• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2025 Igalia S.L.
3  * SPDX-License-Identifier: MIT
4  *
5  * File modification and deletion notification mechanism.
6  */
7 
8 #ifndef _OS_FILE_NOTIFY_H_
9 #define _OS_FILE_NOTIFY_H_
10 
11 #include <stdbool.h>
12 #include <stdio.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 struct os_file_notifier;
19 typedef struct os_file_notifier *os_file_notifier_t;
20 
21 /*
22  * Callback function for file notification.
23  * The `data` parameter is the same as the one passed to os_file_notifier_create().
24  * The `path` parameter is the path of the file that was modified.
25  * The `created` parameter is true if the file was created.
26  * The `deleted` parameter is true if the file was deleted.
27  * The `dir_deleted` parameter is true if the file's parent directory was deleted. No further events will be delivered.
28  */
29 typedef void (*os_file_notify_cb)(void *data, const char *path, bool created, bool deleted, bool dir_deleted);
30 
31 /*
32  * Create a new file notifier which watches the file at the specified path.
33  * If a file notifier cannot be created, NULL is returned with `error_str` (if non-NULL) set to an error message.
34  * Note: The folder must already exist, if the folder containing the file doesn't exist this will fail.
35  *       If the folder is deleted after the file notifier is created, the file notifier will no longer deliver events.
36  *       If the file is deleted and recreated, the file notifier will deliver a deletion event followed by a creation event.
37  *       The file notifier always delivers an event at startup. If the file doesn't exist, the `deleted` parameter will be true.
38  */
39 os_file_notifier_t
40 os_file_notifier_create(const char *path, os_file_notify_cb cb, void *data, const char **error_str);
41 
42 /*
43  * Destroy a file notifier.
44  */
45 void
46 os_file_notifier_destroy(os_file_notifier_t notifier);
47 
48 #ifdef __cplusplus
49 }
50 #endif
51 
52 #endif /* _OS_FILE_NOTIFY_H_ */
53